-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BREAKING CHANGE: Make JWT Codable and generic on claims #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider replacing the use of optionals here with throws
, so that failures to encode or decode a JWT can be debugged / logged.
Sources/SwiftJWT/Base64URL.swift
Outdated
return base64URLEncodedString | ||
} | ||
return nil | ||
extension Data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this source file to reflect the new contents?
Sources/SwiftJWT/JWT.swift
Outdated
/// - Parameter jwt: A String with the encoded and signed JWT. | ||
/// - Parameter verifier: The `JWTVerifier` used to verify the JWT. | ||
/// - Returns: An instance of `JWT` if the decoding succeeds. | ||
public init?(jwtString: String, verifier: JWTVerifier = .none ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why optional initializer versus a failable initializer? There's no way to communicate back the reason for initialization failing (decode error etc)
Sources/SwiftJWT/JWT.swift
Outdated
/// | ||
/// - Note: Sets header.alg with the name of the signing algorithm. | ||
/// - Note: This function will set header.alg field to the name of the signing algorithm. | ||
/// | ||
/// - Parameter using algorithm: The algorithm to sign with. | ||
/// - Returns: A String with the encoded and signed JWT. | ||
/// - Throws: An error thrown during the encoding or signing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer throws
Sources/SwiftJWT/JWT.swift
Outdated
@@ -98,73 +98,18 @@ public struct JWT { | |||
/// - Parameter using algorithm: The algorithm to verify with. | |||
/// - Returns: A Bool indicating whether the verification was successful. | |||
/// - Throws: An error thrown during the verification. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer throws
b1e9bbd
to
ebc3f6a
Compare
Sources/SwiftJWT/JWT.swift
Outdated
/// - Parameter verifier: The `JWTVerifier` used to verify the JWT. | ||
/// - Returns: An instance of `JWT` if the decoding succeeds. | ||
/// - Throws: `JWTError.invalidJWTString` if the jwtString is not base64urlEncoded sections seperated by either 2 or 3 full stops. | ||
/// - Throws: `JWTError.iailedVerification` if the verifier fails to verify the jwtString. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
@@ -20,7 +20,8 @@ import LoggerAPI | |||
|
|||
import Foundation | |||
|
|||
class BlueRSA: EncryptionAlgorithm { | |||
class BlueRSA: SignerAlgorithm, VerifierAlgorithm { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does BlueRSA now provide enough Linux support that we could use this code on Linux and get rid of the Linux-specific RSA
type?
@@ -0,0 +1,37 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this file Data+Base64URLEncoded.swift?
Sources/SwiftJWT/BlueRSA.swift
Outdated
let unsignedJWT = header + "." + claims | ||
guard let unsignedData = unsignedJWT.data(using: .utf8) else { | ||
// replace with custom error | ||
throw NSError(domain: "sign", code: 500, userInfo: [:]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a JWTError
Package.swift
Outdated
@@ -18,16 +18,6 @@ | |||
|
|||
import PackageDescription | |||
|
|||
var listDependencies: [Package.Dependency] = [ | |||
.package(url: "https://github.com/IBM-Swift/HeliumLogger.git", from: "1.7.1"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we do still want to log errors, but this import should be LoggerAPI instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
This pull request makes JWT Codable instead of using [String: Any] dictionaries.
Since this is a breaking change it also includes major refactoring of the project.
The following changes have been made:
Algorithm
into sign and verify algorithms with corresponding private and public key requirements