Skip to content

Commit

Permalink
Adding a configurable HTTP Access Control Filter
Browse files Browse the repository at this point in the history
Also clarifying all exceptions by replacing the fault/reason message to
concrete enumeration/
  • Loading branch information
RockfordWei committed Jan 8, 2018
1 parent daf1b9b commit 61f2f09
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 178 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PackageDescription
import Foundation

var repos = ["Perfect-Crypto"]
var repos = ["Perfect-HTTPServer"]
var targets = [Target(name: "PerfectSSOAuth", dependencies: [])]
let excludes: [String]
let db: String
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Certainly, you can skip the log system if no need, which will log to the console
let man = LoginManager<Profile>(udb: udb)
```

Now you can use the `LoginManager` instance to register, login, load profile, update password and update profile, or drop users:
Now you can use the `LoginManager` instance to register, login, load profile, update password and update profile, or drop user:

#### Register & Login

Expand All @@ -264,6 +264,8 @@ let token = try man.login(id: "someone", password: "secret")
**NOTE**: By default, both user id and password are in a length of **[5,80]** string.
Check [Login / Password Quality Control](#login--password-quality-control) for more information.

**NOTE** For those end users who want user id to be an autoincrement UInt64 id, please fork this repo to make your own edition.

The token generated by `LoginManager.login()` is a JWT for HTTP web servers.

It is supposed to send to the client (browser) as a proof of authentication.
Expand Down
2 changes: 2 additions & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ let token = try man.login(id: "someone", password: "secret")
**注意**: 默认状态下用户名密码长度都是 **[5,80]** 之间的字符串。
详见 [用户名密码质量控制](#login--password-quality-control)

**注意** 如果最终用户希望用可以自动递增的UInt64作为用户id,请自行创建本项目分支版本进行调整。

调用 `LoginManager.login()` 登录后产生的令牌是一个JWT字符串,可以用于HTTP服务器进行权鉴认证。

该令牌应该送回给客户端(浏览器)用于后续安全会话的权限凭证。
Expand Down
44 changes: 43 additions & 1 deletion Sources/PerfectSSOAuth/DataworkUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,48 @@ public enum Exception: Error {

/// an error with a readable reason.
case fault(String)

/// something about json
case json

/// bad user name
case username

/// bad password
case password

/// encryption failure
case encryption

/// digestion failure
case digestion

/// access denied
case access

/// bad format
case malformed

/// bad request
case request

/// expired
case expired

/// violation
case violation

/// record not found
case inexisting

/// operation failure
case operation

/// unsupported
case unsupported

/// connection failure
case connection
}

/// a log file record
Expand Down Expand Up @@ -148,7 +190,7 @@ public final class DataworkUtility {
guard let json = String.init(bytes: data, encoding: .utf8),
let payload = try json.jsonDecode() as? [String:Any]
else {
throw Exception.fault("json decoding failure")
throw Exception.json
}
var result:[Field] = []
for (key, value) in payload {
Expand Down
Loading

0 comments on commit 61f2f09

Please sign in to comment.