IdpCallback

public final class IdpCallback : AbstractCallback, JourneyAware, RequestInterceptor, @unchecked Sendable

A callback that handles federated authentication with an external Identity Provider (IdP) like Google, Facebook, or Apple.

This callback provides all the necessary configuration from the authentication server to perform OAuth 2.0 / OpenID Connect flows with external identity providers. It supports both native SDK integration and browser-based flows.

Usage Example

// The callback is automatically created from server response
if let idpCallback = callback as? IdpCallback {
    let result = await idpCallback.authorize()
    switch result {
    case .success(let idpResult):
        // Authentication successful, proceed with next step
        await continueNode.next()
    case .failure(let error):
        // Handle authentication error
        print("Authentication failed: \(error)")
    }
}

Supported Providers

  • Apple Sign In (Sign in with Apple)
  • Google Sign-In
  • Facebook Login

JourneyAware Conformance

  • Declaration

    Swift

    public var journey: Journey?

Public Properties

  • The name of the identity provider (e.g., “google”, “facebook”).

    Declaration

    Swift

    public private(set) var provider: String { get }
  • The client ID for the application registered with the IdP.

    Declaration

    Swift

    public private(set) var clientId: String { get }
  • The redirect URI configured for the IdP application.

    Declaration

    Swift

    public private(set) var redirectUri: String { get }
  • A list of OAuth 2.0 scopes to request from the IdP.

    Declaration

    Swift

    public private(set) var scopes: [String] { get }
  • A unique value associated with the request to prevent replay attacks.

    Declaration

    Swift

    public private(set) var nonce: String { get }
  • A list of Authentication Context Class Reference values.

    Declaration

    Swift

    public private(set) var acrValues: [String] { get }
  • A signed JWT containing the request parameters.

    Declaration

    Swift

    public private(set) var request: String { get }
  • A URL where the request object can be fetched.

    Declaration

    Swift

    public private(set) var requestUri: String { get }
  • The native handler for the IdP request.

    Declaration

    Swift

    public private(set) var nativeHandler: IdpHandler? { get }
  • Indicates whether the callback accepts JSON responses.

    Declaration

    Swift

    public private(set) var acceptsJSON: Bool { get }

Initialization and Parsing

  • Initializes a new instance of IdpCallback with the provided JSON input.

    Declaration

    Swift

    public override func initValue(name: String, value: Any)

Payload and Interception

  • Constructs the final payload with the token received from the IdP. This method returns a dictionary containing the token and its type, or the JSON response if acceptsJSON is true.

    Declaration

    Swift

    public override func payload() -> [String : Any]

    Return Value

    A dictionary containing the token and its type.

  • A closure that modifies the outgoing request to include additional parameters from the IdP result. This is used to add parameters to the request if the IdP does not accept JSON responses.

    Declaration

    Swift

    public func intercept(context: FlowContext, request: Request) -> Request

    Return Value

    • Request: The modified request with additional parameters added, if applicable.

Public Methods

  • authorize(idpHandler:) Asynchronous

    Initiates the authorization flow with the configured identity provider.

    This method selects the appropriate IdpHandler based on the provider string and invokes its authorize method. On success, it stores the token result to be sent back to the authentication server.

    Throws

    IdpError.unsupportedProvider if no handler can be found, or IdpError.authorizationFailed if the provider’s flow fails.

    Declaration

    Swift

    @MainActor
    public func authorize(idpHandler: IdpHandler? = nil) async -> Result<IdpResult, IdpExceptions>

    Parameters

    idpHandler

    An optional, specific handler to use. If nil, a handler is chosen automatically.