diff --git a/CustomAuthDemo/CustomAuthDemo/ContentView.swift b/CustomAuthDemo/CustomAuthDemo/ContentView.swift index 3fa86e9..a4d763a 100644 --- a/CustomAuthDemo/CustomAuthDemo/ContentView.swift +++ b/CustomAuthDemo/CustomAuthDemo/ContentView.swift @@ -18,10 +18,32 @@ struct ContentView: View { } catch { debugPrint(error) } + } }, label: { Text("Google Login") }) + /* + Button(action: { + Task { + do { + let sub = SingleLoginParams(typeOfLogin: .apple, verifier: "torus-auth0-apple-lrc", clientId: "m1Q0gvDfOyZsJCZ3cucSQEe9XMvl9d9L", redirectURL: "tdsdk://tdsdk/oauthCallback", jwtParams: Auth0ClientOptions(display: nil, prompt: nil, max_age: nil, ui_locales: nil, id_token_hint: nil, arc_values: nil, scope: nil, audience: nil, connection: "apple", domain: "torus-test.auth0.com", client_id: nil, redirect_url: nil, leeway: nil, verifierIdField: nil, isVerifierIdCaseSensitive: true, id_token: nil, access_token: nil, user_info_route: nil)) + + let customAuthArgs = CustomAuthArgs(urlScheme: "tdsdk://tdsdk/oauthCallback", network: .sapphire(.SAPPHIRE_DEVNET), enableOneKey: true, web3AuthClientId: "BAh0_c0G8U8GoMUIYDcX_f65fU_N9O0mWz6xM6RqBfaaAlYsTha8oOef7ifXPjd_bCTJdfWQemmrbY6KepC7XNA") + + let customAuth = try CustomAuth(config: customAuthArgs) + let torusLoginResponse = try await customAuth.triggerLogin(args: sub) + let encoded = try JSONEncoder().encode(torusLoginResponse) + debugPrint(String(data: encoded, encoding: .utf8)!) + } catch { + debugPrint(error) + } + + } + }, label: { + Text("Apple Login") + }) + */ } } } diff --git a/Sources/CustomAuth/Common/LoginParams/Auth0ClientOptions.swift b/Sources/CustomAuth/Common/LoginParams/Auth0ClientOptions.swift index 9bfb19b..8b10396 100644 --- a/Sources/CustomAuth/Common/LoginParams/Auth0ClientOptions.swift +++ b/Sources/CustomAuth/Common/LoginParams/Auth0ClientOptions.swift @@ -11,7 +11,7 @@ public class Auth0ClientOptions: BaseLoginOptions { public let access_token: String? public let user_info_route: String? - public init(customParams: [String: String] = [:], display: String? = nil, prompt: String? = nil, max_age: Int? = nil, ui_locales: String? = nil, id_token_hint: String? = nil, arc_values: String? = nil, scope: String? = nil, audience: String? = nil, connection: String? = nil, domain: String? = nil, client_id: String? = nil, redirect_url: String? = nil, leeway: Int? = nil, verifierIdField: String? = nil, isVerifierIdCaseSensitive: Bool = false, id_token: String? = nil, access_token: String? = nil, user_info_route: String? = nil) { + public init(display: String? = nil, prompt: String? = nil, max_age: Int? = nil, ui_locales: String? = nil, id_token_hint: String? = nil, arc_values: String? = nil, scope: String? = nil, audience: String? = nil, connection: String? = nil, domain: String? = nil, client_id: String? = nil, redirect_url: String? = nil, leeway: Int? = nil, verifierIdField: String? = nil, isVerifierIdCaseSensitive: Bool = false, id_token: String? = nil, access_token: String? = nil, user_info_route: String? = nil) { self.domain = domain self.redirect_url = redirect_url self.leeway = leeway @@ -22,7 +22,7 @@ public class Auth0ClientOptions: BaseLoginOptions { self.user_info_route = user_info_route self.client_id = client_id - super.init(customParams: customParams, display: display, prompt: prompt, max_age: max_age, ui_locales: ui_locales, id_token_hint: id_token_hint, arc_values: arc_values, scope: scope, audience: audience, connection: connection) + super.init(display: display, prompt: prompt, max_age: max_age, ui_locales: ui_locales, id_token_hint: id_token_hint, arc_values: arc_values, scope: scope, audience: audience, connection: connection) } required init(from decoder: any Decoder) throws { diff --git a/Sources/CustomAuth/Common/LoginParams/BaseLoginOptions.swift b/Sources/CustomAuth/Common/LoginParams/BaseLoginOptions.swift index 0f1ef58..8046b0a 100644 --- a/Sources/CustomAuth/Common/LoginParams/BaseLoginOptions.swift +++ b/Sources/CustomAuth/Common/LoginParams/BaseLoginOptions.swift @@ -1,7 +1,6 @@ import Foundation public class BaseLoginOptions: Codable { - public let customParams: [String: String] public let display: String? public let prompt: String? public let max_age: Int? @@ -12,8 +11,7 @@ public class BaseLoginOptions: Codable { public let audience: String? public let connection: String? - public init(customParams: [String: String] = [:], display: String? = nil, prompt: String? = nil, max_age: Int? = nil, ui_locales: String? = nil, id_token_hint: String? = nil, arc_values: String? = nil, scope: String? = nil, audience: String? = nil, connection: String? = nil) { - self.customParams = customParams + public init(display: String? = nil, prompt: String? = nil, max_age: Int? = nil, ui_locales: String? = nil, id_token_hint: String? = nil, arc_values: String? = nil, scope: String? = nil, audience: String? = nil, connection: String? = nil) { self.display = display self.prompt = prompt self.max_age = max_age diff --git a/Sources/CustomAuth/Handlers/MockLoginHandler.swift b/Sources/CustomAuth/Handlers/MockLoginHandler.swift index 66c7055..1c6e50f 100644 --- a/Sources/CustomAuth/Handlers/MockLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/MockLoginHandler.swift @@ -22,12 +22,9 @@ class MockLoginHandler: AbstractLoginHandler { urlComponents.scheme = "https" urlComponents.host = jwtParams?.domain urlComponents.path = "/authorize" - - let encoder = JSONEncoder() - encoder.outputFormatting = .sortedKeys - let hashParam = String(data: try encoder.encode(params), encoding: .utf8)! - urlComponents.setQueryItems(with: ["hash": hashParam]) - + urlComponents.fragment = params.compactMap({ (key, value) -> String in + return "\(key)=\(value)" + }).joined(separator: "&") finalUrl = urlComponents }