Conversation
…ura-CredentialsHTTP into typeSafeMiddleware
|
The tests are currently failing since they require typeSafeMiddleware which will only be available in Kitura 2.4. and it will need TypeSafeCredentials to be tagged. |
README.md
Outdated
|
|
||
| public let id: String | ||
|
|
||
| public static let users = ["John" : "12345", "Mary" : "qwerasdf"] |
There was a problem hiding this comment.
Probably make this private!
|
@Andrew-Lees11 FYI, Kitura and Credentials dependencies are merged and tagged - I have restarted the CI. |
Codecov Report
@@ Coverage Diff @@
## master #49 +/- ##
==========================================
- Coverage 80.23% 79.89% -0.35%
==========================================
Files 2 3 +1
Lines 167 199 +32
==========================================
+ Hits 134 159 +25
- Misses 33 40 +7
Continue to review full report at Codecov.
|
|
|
||
| static var allTests : [(String, (TestTypeSafeBasic) -> () throws -> Void)] { | ||
| return [ | ||
| ("testTypeSafeNoCredentials", testTypeSafeNoCredentials), |
There was a problem hiding this comment.
This array is missing some of the tests!
There was a problem hiding this comment.
Tests have been added and this file has been added to linux main
| userid = requestUser | ||
| password = requestPassword | ||
| } | ||
| else { |
There was a problem hiding this comment.
Please put the else on the previous line.
| if let selfInstance = selfInstance { | ||
| onSuccess(selfInstance) | ||
| } | ||
| else { |
| } | ||
| let credentials = userAuthorization.components(separatedBy: ":") | ||
| guard credentials.count >= 2 else { | ||
| onFailure(.badRequest, nil) |
| let body = try response?.readString() | ||
| XCTAssertEqual(body,"{\"name\":\"Mary\",\"provider\":\"HTTPBasic\"}") | ||
| } | ||
| catch{ |
There was a problem hiding this comment.
Merge with previous line.
| static var realm: String { get } | ||
|
|
||
| /// The closure which takes a username and password and returns a TypeSafeHTTPBasic instance on success or nil on failure. | ||
| static var verifyPassword: ((String, String, @escaping (Self?) -> Void) -> Void) { get } |
There was a problem hiding this comment.
This isn't very type-safe, did you consider replacing these Strings with something protocol-based?
There was a problem hiding this comment.
I think we should replace with something like
static func verifyPassword(username: String, password, String, callback: @escaping (Self?) -> Void) -> VoidXcode will auto-complete this much nicer than the version where we define a closure signature, and apply the labels which indicates how to handle each argument.
|
|
||
| public static let realm = "Login message" | ||
|
|
||
| public static var verifyPassword: ((String, String, @escaping (MyHTTPBasic?) -> Void) -> Void) = |
There was a problem hiding this comment.
Usage example needs updating now that this is a function
| /// The realm for which these credentials are valid (defaults to "User") | ||
| static var realm: String { get } | ||
|
|
||
| /// The closure which takes a username and password and returns a TypeSafeHTTPBasic instance on success or nil on failure. |
There was a problem hiding this comment.
Comment needs updating now that this is a function
Once typeSafeCredentials is merged we can implement HTTP basic auth using typeSafeMiddlware.
Docs description:
A
TypeSafeCredentialsplugin for HTTP basic authentication. This protocol will be implemented by a Swift object defined by the user. The plugin must implement averifyPasswordfunction which takes a username and password as input and returns an instance ofSelfon success ornilon failure. This instance must contain the authenticationprovider(defaults to "HTTPBasic") and anid, uniquely identifying the user. The users object can then be used in TypeSafeMiddlware routes to authenticate with HTTP basic.