This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
470241a
commit dfdb80c
Showing
9 changed files
with
33 additions
and
88 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
public struct Authorization { | ||
public let header: String | ||
public struct AuthorizationHeader { | ||
public let string: String | ||
|
||
public init(header: String) { | ||
self.header = header | ||
public init(string: String) { | ||
self.string = string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import Core | ||
|
||
extension Authorization { | ||
extension AuthorizationHeader { | ||
public var basic: Password? { | ||
guard let range = header.range(of: "Basic ") else { | ||
guard let range = string.range(of: "Basic ") else { | ||
return nil | ||
} | ||
|
||
let token = header.substring(from: range.upperBound) | ||
|
||
let token = string.substring(from: range.upperBound) | ||
|
||
let decodedToken = token.makeBytes().base64Decoded.string | ||
guard let separatorRange = decodedToken.range(of: ":") else { | ||
return nil | ||
} | ||
|
||
let apiKeyID = decodedToken.substring(to: separatorRange.lowerBound) | ||
let apiKeySecret = decodedToken.substring(from: separatorRange.upperBound) | ||
let username = decodedToken.substring(to: separatorRange.lowerBound) | ||
let password = decodedToken.substring(from: separatorRange.upperBound) | ||
|
||
return Password(username: apiKeyID, password: apiKeySecret) | ||
return Password(username: username, password: password) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
extension Authorization { | ||
extension AuthorizationHeader { | ||
public var bearer: Token? { | ||
guard let range = header.range(of: "Bearer ") else { | ||
guard let range = string.range(of: "Bearer ") else { | ||
return nil | ||
} | ||
|
||
let token = header.substring(from: range.upperBound) | ||
let token = string.substring(from: range.upperBound) | ||
return Token(string: token) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters