Skip to main content
Function Signature
A PortalAuth method. Fetches a fresh authorize URL from Portal and returns it; your app opens it (for example with UIApplication.shared.open), later reads the redirect with parseRedirect and completes it with completeOAuthLogin. For a flow that also owns the browser, use signInWithGoogle. Returns
  • AuthorizeUrlResult: Contains the following:
    • authorizeUrl: String, the Google authorize URL, trimmed of surrounding whitespace.
Throws
  • PortalAuthError.authMethodUnavailable(.google): Google is not enabled for this auth environment. Not retryable; check getMethods().
  • PortalAuthError.accountAbstractionUnavailable(message:): isAccountAbstracted: true was requested but gas sponsorship is not enabled or configured.
  • PortalAuthError.sessionStorageFailure(message:): The sign-in could not be stored in the Keychain, so no URL is returned and no sign-in is started. Retrying may succeed.
  • PortalRequestsError.unauthorized: The redirectUrl is not on the environment’s allow list, the Auth Environment ID does not match an environment with authentication switched on, or an enabled provider is missing its credentials in the dashboard. That last case fails the call for every provider, not only the misconfigured one.
  • Other transport errors unchanged.
Notes
  • Bound to this device. Each call stores a one-time code verifier in the Keychain before it returns the URL and replaces the one stored by any earlier loginWith* or signInWith* call, so only the redirect of the URL whose verifier was stored last can complete, within 15 minutes, on this device: on one instance that is the URL returned last; across instances sharing the Auth Environment ID, whichever start stored its verifier last. The sign-in survives your app being terminated while the browser is open. Calling clearPersistedSession() afterwards cancels it. You keep no record of the sign-in yourself: completeOAuthLogin refuses a redirect this device did not start. Available starting from SDK version 8.2.0; see Google and Apple sign-ins are bound to the device.
  • Call it on every tap and never cache the result. The URL embeds a single-use state shared by both provider URLs in one backend response, so a stale URL fails at the provider with no useful message.
  • The redirect arrives through the OS: onOpenURL in SwiftUI, or your scene or app delegate in UIKit. This path works with an https:// Universal Link redirect, which only your app receives. With a custom scheme, another app that takes the redirect cannot use the grant, but the user’s sign-in fails. See Register your redirect.
  • If the sign-in does not complete — the user cancels, Google rejects it, or it fails for any other reason — Portal redirects to your redirectUrl with an error in the URL (error=oauth_failed), which parseRedirect returns as .failed(error:).
  • Available starting from SDK version 8.0.0.
Example Usage
Related Documentation