Skip to content

Commit

Permalink
make redirect config naming more generic (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepitre authored Mar 25, 2024
1 parent d100b4d commit 0aad090
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sources/API/Models/Clerk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// File.swift
//
// RedirectConfig.swift
//
//
// Created by Mike Pitre on 3/19/24.
//
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/API/Models/SignIn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Sources/API/Models/SignUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/API/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/API/Utils/ExternalAuthWebSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class ExternalAuthWebSession: NSObject {

func start() async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) 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()
Expand Down

0 comments on commit 0aad090

Please sign in to comment.