From 0aad090ac7dd32e161093be346401b3ecbb844f1 Mon Sep 17 00:00:00 2001 From: Mike Pitre Date: Mon, 25 Mar 2024 13:23:59 -0400 Subject: [PATCH] make redirect config naming more generic (#29) --- Sources/API/Models/Clerk.swift | 2 +- .../{OAuthSettings.swift => RedirectConfig.swift} | 12 ++++++------ Sources/API/Models/SignIn.swift | 4 ++-- Sources/API/Models/SignUp.swift | 2 +- Sources/API/Models/User.swift | 2 +- Sources/API/Utils/ExternalAuthWebSession.swift | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) rename Sources/API/Models/{OAuthSettings.swift => RedirectConfig.swift} (70%) diff --git a/Sources/API/Models/Clerk.swift b/Sources/API/Models/Clerk.swift index 48abdf6f..6db70ab5 100644 --- a/Sources/API/Models/Clerk.swift +++ b/Sources/API/Models/Clerk.swift @@ -110,7 +110,7 @@ final public class Clerk: ObservableObject, @unchecked Sendable { private(set) public var frontendAPIURL: String = "" /// The configurable OAuth settings. For example: `redirectUrl`, `callbackUrlScheme` - public var oauthSettings = OAuthSettings() + public var redirectConfig = RedirectConfig() /// The currently active Session, which is guaranteed to be one of the sessions in Client.sessions. If there is no active session, this field will be null. public var session: Session? { diff --git a/Sources/API/Models/OAuthSettings.swift b/Sources/API/Models/RedirectConfig.swift similarity index 70% rename from Sources/API/Models/OAuthSettings.swift rename to Sources/API/Models/RedirectConfig.swift index 074943f8..b2ef0f2d 100644 --- a/Sources/API/Models/OAuthSettings.swift +++ b/Sources/API/Models/RedirectConfig.swift @@ -1,6 +1,6 @@ // -// File.swift -// +// RedirectConfig.swift +// // // Created by Mike Pitre on 3/19/24. // @@ -9,19 +9,19 @@ import Foundation extension Clerk { - public struct OAuthSettings { - /// - Parameter redirectUrl: The URL to redirect back to one the OAuth flow has completed successfully or unsuccessfully.By default, this is set to `{YOUR_APPS_BUNDLE_IDENTIFIER}://oauth_callback`. + public struct RedirectConfig { + /// - Parameter redirectUrl: The URL to redirect back to once an external flow has completed successfully or unsuccessfully. By default, this is set to `{YOUR_APPS_BUNDLE_IDENTIFIER}://callback`. /// - Parameter callbackUrlScheme: The custom URL scheme that the app expects in the callback URL. By default, this is set to your app's bundle identifier. public init( - redirectUrl: String = "\(Bundle.main.bundleIdentifier ?? "")://oauth_callback", + redirectUrl: String = "\(Bundle.main.bundleIdentifier ?? "")://callback", callbackUrlScheme: String = Bundle.main.bundleIdentifier ?? "" ) { self.redirectUrl = redirectUrl self.callbackUrlScheme = callbackUrlScheme } - /// The URL to redirect back to one the OAuth flow has completed successfully or unsuccessfully. + /// The URL to redirect back to once the external flow has completed successfully or unsuccessfully. public var redirectUrl: String /// The custom URL scheme that the app expects in the callback URL. public var callbackUrlScheme: String diff --git a/Sources/API/Models/SignIn.swift b/Sources/API/Models/SignIn.swift index 020c53f1..13fb5d02 100644 --- a/Sources/API/Models/SignIn.swift +++ b/Sources/API/Models/SignIn.swift @@ -167,7 +167,7 @@ public struct SignIn: Codable, Sendable { case .identifier(let identifier, let password): return .init(identifier: identifier, password: password) case .externalProvider(let provider): - return .init(strategy: provider.data.strategy, redirectUrl: Clerk.shared.oauthSettings.redirectUrl, actionCompleteRedirectUrl: Clerk.shared.oauthSettings.redirectUrl) + return .init(strategy: provider.data.strategy, redirectUrl: Clerk.shared.redirectConfig.redirectUrl, actionCompleteRedirectUrl: Clerk.shared.redirectConfig.redirectUrl) case .transfer: return .init(transfer: true) } @@ -233,7 +233,7 @@ public struct SignIn: Codable, Sendable { case .emailCode, .resetPasswordEmailCode: return .init(strategy: strategy.stringValue, emailAddressId: factorId(for: strategy)) // case .emailLink: -// return .init(strategy: strategy.stringValue, emailAddressId: factorId(for: strategy), redirectUrl: Clerk.shared.frontendAPIURL.replacingOccurrences(of: ".clerk", with: "") + "/sign-in/verify") +// return .init(strategy: strategy.stringValue, emailAddressId: factorId(for: strategy), redirectUrl: Clerk.shared.redirectConfig.redirectUrl) case .phoneCode, .resetPasswordPhoneCode: return .init(strategy: strategy.stringValue, phoneNumberId: factorId(for: strategy)) case .saml: diff --git a/Sources/API/Models/SignUp.swift b/Sources/API/Models/SignUp.swift index df58a6dd..63dc09f2 100644 --- a/Sources/API/Models/SignUp.swift +++ b/Sources/API/Models/SignUp.swift @@ -177,7 +177,7 @@ public struct SignUp: Codable, Sendable { case .standard(let emailAddress, let password, let firstName, let lastName, let username, let phoneNumber): return .init(firstName: firstName, lastName: lastName, password: password, emailAddress: emailAddress, phoneNumber: phoneNumber, username: username) case .externalProvider(let provider): - return .init(strategy: .externalProvider(provider), redirectUrl: Clerk.shared.oauthSettings.redirectUrl, actionCompleteRedirectUrl: Clerk.shared.oauthSettings.redirectUrl) + return .init(strategy: .externalProvider(provider), redirectUrl: Clerk.shared.redirectConfig.redirectUrl, actionCompleteRedirectUrl: Clerk.shared.redirectConfig.redirectUrl) case .transfer: return .init(transfer: true) } diff --git a/Sources/API/Models/User.swift b/Sources/API/Models/User.swift index 029b6435..5a03a152 100644 --- a/Sources/API/Models/User.swift +++ b/Sources/API/Models/User.swift @@ -265,7 +265,7 @@ extension User { let additionalScopes: [String]? /// The URL to redirect back to one the oauth flow has completed successfully or unsuccessfully. - private let redirectUrl: String = Clerk.shared.oauthSettings.redirectUrl + private let redirectUrl: String = Clerk.shared.redirectConfig.redirectUrl } /// Generates a TOTP secret for a user that can be used to register the application on the user's authenticator app of choice. Note that if this method is called again (while still unverified), it replaces the previously generated secret. diff --git a/Sources/API/Utils/ExternalAuthWebSession.swift b/Sources/API/Utils/ExternalAuthWebSession.swift index f7c8777b..e4b81b5f 100644 --- a/Sources/API/Utils/ExternalAuthWebSession.swift +++ b/Sources/API/Utils/ExternalAuthWebSession.swift @@ -25,7 +25,7 @@ final class ExternalAuthWebSession: NSObject { func start() async throws { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in - let webAuthSession = ASWebAuthenticationSession(url: url, callbackURLScheme: Clerk.shared.oauthSettings.callbackUrlScheme) { callbackUrl, error in + let webAuthSession = ASWebAuthenticationSession(url: url, callbackURLScheme: Clerk.shared.redirectConfig.callbackUrlScheme) { callbackUrl, error in if let error = error { if case ASWebAuthenticationSessionError.canceledLogin = error { continuation.resume()