Skip to main content
handleRedirect is deprecated in SDK version 8.2.0 and will be removed in the next major version. It completes a magic link in one step, without first showing the user the email address and waiting for them to confirm, which lets a user be signed in from a link they did not request. Read redirects with parseRedirect instead, then complete a magic link with getMagicLinkDetails and, once the user confirms the email, confirmMagicLink, and a Google or Apple sign-in with completeOAuthLogin. See Migrate from handleRedirect.
Function Signature
A PortalAuth method. Reads the URL with parseRedirect and completes whatever it reads in one step: a magic link as confirmMagicLink would, without the confirmation, and a Google or Apple redirect as completeOAuthLogin would, bound to this device in the same way. Parameters
  • url: The URL iOS delivered to your app, as a URL (from onOpenURL, your scene delegate or your app delegate) or a String. The URL overload forwards absoluteString, so percent-encoding stays intact and the grant is decoded exactly once.
Returns
  • AuthResult?:
    • nil: The URL is not for this instance — whenever parseRedirect returns nil: it does not match redirectUrl, carries both authMethod and login_type, carries no error parameter and either no token (or an empty or whitespace-only one) or no recognized auth-method marker, is empty, or is longer than 8192 UTF-16 code units. Let your other URL handlers try.
    • .authenticated(AuthenticatedResult): The sign-in is complete. session is already saved to the Keychain; pass it to Portal(credentials:).
    • .totpRequired(TotpRequiredResult): A two-factor code is required. Nothing is persisted; complete with verifyTotp.
Throws
  • PortalAuthError.authenticationFailed(error:): The URL matches redirectUrl and carries an error parameter, for example oauth_failed. Thrown even if a token is also present, and before any network call. The value is bounded to 100 characters.
  • PortalAuthError.oauthFlowNotStarted: A Google or Apple redirect arrived with no sign-in in progress on this device, as completeOAuthLogin describes. Nothing is sent, unless clearPersistedSession() cancels the exchange while it runs. Start a new sign-in. Available starting from SDK version 8.2.0.
  • PortalAuthError.invalidGrantResponse: The exchange returned neither a session token nor a userJwt.
  • PortalAuthError.malformedResponse(path:missing:): The response did not carry the documented fields.
  • PortalAuthError.sessionStorageFailure(message:): The Keychain failed this time: the Google or Apple sign-in in progress could not be read (nothing was sent), or the session could not be saved, so the sign-in is not returned (the grant is already spent). In both cases calling handleRedirect again with the same URL on the same instance retries: the exchange in the first case, the write in the second, without re-sending the grant.
  • PortalRequestsError.unauthorized: Portal rejected the grant: it expired, was already exchanged, was issued for a different environment, or its sign-in method has since been disabled — or, for Google or Apple, it belongs to a sign-in other than the one in progress on this device. Also thrown when a remembered session has since been invalidated. Unlike confirmMagicLink, a refused magic link is reported this way too, not as PortalAuthError.grantRejected.
  • Other transport errors unchanged.
Notes
  • Changed in 8.2.0: returns nil for a URL that carries both authMethod and login_type (previously exchanged as a magic link) and for a token that is only whitespace. Portal never sends either.
  • Each time it is given a magic link it logs a deprecation warning at the .warn level. The log level is shared, starts at .none, is reset to .none by every Portal you construct, and can only be raised with portal.setLogLevel(_:) after that; see Configure log level. A redirect is usually completed before any Portal exists, so rely on Xcode’s deprecation warning at the call site.
  • It shares the remembered result with confirmMagicLink and completeOAuthLogin: a grant completed through either path replays the same way through the other, on the same instance and in the same process, while the session is live. A redirect that failed on a dropped connection is not remembered, so it can be retried; if Portal spent the grant before the connection dropped, the retry throws PortalRequestsError.unauthorized and the user needs a new sign-in. clearPersistedSession() drops the memory, and after the app is terminated the recovery is restoreSession(); a Google or Apple redirect delivered again then fails, usually with oauthFlowNotStarted.
  • A grant that stopped at .totpRequired replays as the same step. Once verifyTotp accepts the code, the same grant replays as the .authenticated result it resolved to.
  • Never log the raw URL; it contains the grant.
  • Available starting from SDK version 8.0.0. Deprecated in 8.2.0.
Example Usage Replace a handleRedirect call with parseRedirect and a completion per case:
Related Documentation