Skip to content

Commit

Permalink
passwordless
Browse files Browse the repository at this point in the history
  • Loading branch information
metalurgical committed Jul 29, 2024
1 parent 4b2ebcf commit b9f81e0
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Common/LoginParams/LoginType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public enum LoginType: String, Equatable, Hashable, Codable {
case weibo
case line
case email_password
case jwt
case passwordless
}
2 changes: 1 addition & 1 deletion Sources/CustomAuth/Handlers/HandlerFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down
6 changes: 3 additions & 3 deletions Sources/CustomAuth/Handlers/JWTLoginHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
10 changes: 8 additions & 2 deletions Sources/CustomAuth/Handlers/MockLoginHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
6 changes: 3 additions & 3 deletions Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
}
5 changes: 2 additions & 3 deletions Sources/CustomAuth/Helpers/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit b9f81e0

Please sign in to comment.