diff --git a/Package.resolved b/Package.resolved index bffe33b..28b458e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/torus-utils-swift.git", "state" : { - "branch" : "feature_updates", - "revision" : "f92916568e3fec9a3118a65148d97893b9c6335f" + "revision" : "7788752bed699b3d34e78c2c51174f814d02610b", + "version" : "9.0.0" } } ], diff --git a/Sources/CustomAuth/Common/LoginParams/LoginType.swift b/Sources/CustomAuth/Common/LoginParams/LoginType.swift index 8bb77a4..d260882 100644 --- a/Sources/CustomAuth/Common/LoginParams/LoginType.swift +++ b/Sources/CustomAuth/Common/LoginParams/LoginType.swift @@ -13,5 +13,5 @@ public enum LoginType: String, Equatable, Hashable, Codable { case weibo case line case email_password - case jwt + case passwordless } diff --git a/Sources/CustomAuth/Handlers/HandlerFactory.swift b/Sources/CustomAuth/Handlers/HandlerFactory.swift index a8075b7..5c258d9 100644 --- a/Sources/CustomAuth/Handlers/HandlerFactory.swift +++ b/Sources/CustomAuth/Handlers/HandlerFactory.swift @@ -30,7 +30,7 @@ public class HandlerFactory { case .weibo: break case .line: break case .email_password: break - case .jwt: break + case .passwordless: return try PasswordlessLoginHandler(clientId: params.clientId, verifier: params.verifier, urlScheme: params.urlScheme, redirectURL: params.redirectURL, typeOfLogin: params.typeOfLogin, jwtParams: params.jwtParams, customState: params.customState) } diff --git a/Sources/CustomAuth/Handlers/JWTLoginHandler.swift b/Sources/CustomAuth/Handlers/JWTLoginHandler.swift index bdbec48..92c65d4 100644 --- a/Sources/CustomAuth/Handlers/JWTLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/JWTLoginHandler.swift @@ -55,7 +55,7 @@ class JWTLoginHandler: AbstractLoginHandler { ], uniquingKeysWith: { _, new in new }) urlComponents.scheme = "https" urlComponents.host = jwtParams?.domain - urlComponents.path = "/authorize" + urlComponents.path = "/passwordless/start" urlComponents.setQueryItems(with: params) finalUrl = urlComponents @@ -86,7 +86,7 @@ class JWTLoginHandler: AbstractLoginHandler { let (data, _) = try await URLSession.shared.data(for: urlRequest) let result = try JSONDecoder().decode(Auth0UserInfo.self, from: data) - return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) + return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try jwtParams?.verifierIdField ?? getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) } if idToken == nil { @@ -95,7 +95,7 @@ class JWTLoginHandler: AbstractLoginHandler { let decodedToken = try decode(jwt: idToken!) let result = Auth0UserInfo(picture: decodedToken.body["picture"] as? String ?? "", email: decodedToken.body["email"] as? String ?? "", name: decodedToken.body["name"] as? String ?? "", sub: decodedToken.body["sub"] as? String ?? "", nickname: decodedToken.body["nickname"] as? String ?? "") - return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) + return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try jwtParams?.verifierIdField ?? getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) } } } diff --git a/Sources/CustomAuth/Handlers/MockLoginHandler.swift b/Sources/CustomAuth/Handlers/MockLoginHandler.swift index 6bdfe9e..c079edb 100644 --- a/Sources/CustomAuth/Handlers/MockLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/MockLoginHandler.swift @@ -11,11 +11,17 @@ class MockLoginHandler: AbstractLoginHandler { if jwtParams == nil { throw CASDKError.invalidAuth0Options } + + var connection = jwtParams?.connection + if connection == nil { + connection = loginToConnection(loginType: typeOfLogin) + } var params: [String: String] = try (JSONSerialization.jsonObject(with: try JSONEncoder().encode(jwtParams), options: []) as! [String: String]) params.merge([ "state": try state(), "client_id": clientId, + "connection": connection!, "nonce": nonce, ], uniquingKeysWith: { _, new in new }) @@ -70,7 +76,7 @@ class MockLoginHandler: AbstractLoginHandler { let result = try JSONDecoder().decode(Auth0UserInfo.self, from: data) - return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) + return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try jwtParams?.verifierIdField ?? getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) } if idToken == nil { @@ -79,7 +85,7 @@ class MockLoginHandler: AbstractLoginHandler { let decodedToken = try decode(jwt: idToken!) let result = Auth0UserInfo(picture: decodedToken.body["picture"] as? String ?? "", email: decodedToken.body["email"] as? String ?? "", name: decodedToken.body["name"] as? String ?? "", sub: decodedToken.body["sub"] as? String ?? "", nickname: decodedToken.body["nickname"] as? String ?? "") - return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) + return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try jwtParams?.verifierIdField ?? getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) } } } diff --git a/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift b/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift index aec6415..c38d9d4 100644 --- a/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift @@ -4,7 +4,7 @@ import JWTDecode class PasswordlessLoginHandler: AbstractLoginHandler { private var response_type: String = "token id_token" private var scope: String = "openid profile email" - private var prompt: String = "Login" + private var prompt: String = "login" override public init(clientId: String, verifier: String, urlScheme: String, redirectURL: String, typeOfLogin: LoginType, jwtParams: Auth0ClientOptions? = nil, customState: TorusGenericContainer? = nil) throws { try super.init(clientId: clientId, verifier: verifier, urlScheme: urlScheme, redirectURL: redirectURL, typeOfLogin: typeOfLogin, jwtParams: jwtParams, customState: customState) @@ -70,7 +70,7 @@ class PasswordlessLoginHandler: AbstractLoginHandler { let (data, _) = try await URLSession.shared.data(for: urlRequest) let result = try JSONDecoder().decode(Auth0UserInfo.self, from: data) - return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) + return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try jwtParams?.verifierIdField ?? getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) } if idToken == nil { @@ -79,7 +79,7 @@ class PasswordlessLoginHandler: AbstractLoginHandler { let decodedToken = try decode(jwt: idToken!) let result = Auth0UserInfo(picture: decodedToken.body["picture"] as? String ?? "", email: decodedToken.body["email"] as? String ?? "", name: decodedToken.body["name"] as? String ?? "", sub: decodedToken.body["sub"] as? String ?? "", nickname: decodedToken.body["nickname"] as? String ?? "") - return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) + return TorusVerifierResponse(email: result.email, name: result.name, profileImage: result.picture, verifier: verifier, verifierId: try jwtParams?.verifierIdField ?? getVerifierId(userInfo: result, typeOfLogin: typeOfLogin, verifierIdField: verifierIdField, isVerifierIdCaseSensitive: isVerifierCaseSensitive), typeOfLogin: typeOfLogin) } } } diff --git a/Sources/CustomAuth/Helpers/Common.swift b/Sources/CustomAuth/Helpers/Common.swift index 51fed94..350fb89 100644 --- a/Sources/CustomAuth/Helpers/Common.swift +++ b/Sources/CustomAuth/Helpers/Common.swift @@ -13,10 +13,9 @@ func loginToConnection(loginType: LoginType) -> String { case .twitter: break case .weibo: break case .line: break - case .jwt: break case .email_password: return "Username-Password-Authentication" + case .passwordless: return "email" } - return loginType.rawValue } @@ -48,8 +47,8 @@ func getVerifierId( case .twitter: return sub case .weibo: return sub case .line: return sub - case .jwt: return sub case .email_password: return name + case .passwordless: return name } }