Skip to main content
Function Signature
A PortalAuth method. Fetches a fresh authorize URL, presents Apple in an ASWebAuthenticationSession sheet from the anchor set with setAuthPresentationAnchor(_:), receives the callback inside the sheet, and exchanges the token through the same code path as completeOAuthLogin. Replay protection, persist-before-return and the two-factor branch behave identically. Returns
  • AuthResult: One of:
    • .authenticated(AuthenticatedResult): The sign-in is complete. session is a PortalSession already saved to the Keychain; pass it to Portal(credentials:). clientId and isAccountAbstracted describe the client Portal resolved.
    • .totpRequired(TotpRequiredResult): The environment requires a two-factor code. Nothing is persisted; complete the sign-in with verifyTotp.
Throws
  • PortalAuthSignInError.unavailable: No presentation anchor was set (or its window was deallocated), the redirectUrl is not a custom URL scheme, or the system refused to start the session.
  • PortalAuthSignInError.signInInProgress: Another signInWith* call is still running.
  • PortalAuthSignInError.closed: The user dismissed the sheet, or the calling task was cancelled.
  • PortalAuthSignInError.callbackIncomplete: The browser returned a callback that carried no Apple sign-in result for this instance, such as a Google result or a magic link. Nothing is exchanged.
  • PortalAuthError.authMethodUnavailable(.apple): Apple is not enabled for this auth environment.
  • PortalAuthError.authenticationFailed(error:): The callback URL carried an error parameter instead of a grant (oauth_failed): the sign-in did not complete, whether the user cancelled, the provider rejected it, or it failed for any other reason.
  • PortalAuthError.sessionStorageFailure(message:): The sign-in could not be stored in the Keychain before the sheet opened (no sheet is shown; retrying may succeed), could not be read when the sheet returned (nothing was sent), or the session could not be saved to the Keychain afterwards (the sign-in is not returned unsaved). Start a new sign-in.
  • PortalAuthError.oauthFlowNotStarted: The sign-in was replaced by a loginWithGoogle() / loginWithApple() call (or a signInWith* call on another instance), or cancelled by clearPersistedSession(), while the sheet was open: its grant is not exchanged. Also thrown when clearPersistedSession() on this instance cancels the exchange after the sheet returned (the grant may then be spent). Start a new sign-in. Available starting from SDK version 8.2.0.
  • PortalRequestsError.unauthorized: Portal refused the authorize URL request (the redirectUrl is not allow-listed, the Auth Environment ID is wrong, or an enabled provider is missing its credentials), or rejected the grant.
  • Other PortalAuthError cases completeOAuthLogin can throw, and transport errors unchanged.
Notes
  • Call setAuthPresentationAnchor(_:) with your window before signing in. The anchor is held weakly.
  • Requires a custom-scheme redirectUrl such as myapp://auth/callback. An https:// Universal Link is not supported by signInWith* in this release and throws .unavailable; use loginWithApple, parseRedirect and completeOAuthLogin for that.
  • The callback is matched inside the browser session and never routed through the OS URL handler, so another app that registers the same scheme cannot intercept it. This is the recommended OAuth path.
  • One sign-in at a time. Both provider URLs share a single-use state, so a concurrent signInWith* call on the same instance throws .signInInProgress rather than invalidating the first.
  • Bound to this device, like every Google or Apple sign-in: the SDK stores a one-time code verifier in the Keychain and sends it with the grant. It shares the one sign-in in progress per auth environment with loginWithGoogle / loginWithApple, and its verifier is removed when the call returns, whatever the outcome. Available starting from SDK version 8.2.0; see Google and Apple sign-ins are bound to the device.
  • Apple posts the result to Portal’s callback URL, which you register as a Return URL on your Services ID; Portal then redirects into the sheet’s callback. Your app only ever sees the final result.
  • Portal identifies an end user by email. A user who picks Hide My Email becomes a distinct end user, with a distinct wallet, from the same person signing in with Google or a magic link. See Apple OAuth.
  • Portal delivers Sign in with Apple as a web flow, so the button is your own control. Follow Apple’s Human Interface Guidelines for the Sign in with Apple button. If your app also offers Google sign-in, review App Store Review Guideline 4.8 (Login Services), which may require you to offer Sign in with Apple as well.
  • Cancelling the calling Task before the sheet returns its result dismisses the sheet and throws .closed, and nothing is exchanged. Once the result has arrived, the exchange runs to completion even if the task is cancelled. On sign-out, cancel the task to close the sheet: clearPersistedSession() cancels the sign-in itself, so a callback that still arrives is refused with oauthFlowNotStarted, but it cannot close the sheet. Do not adopt a result that returns after the sign-out.
  • Completes only an Apple result from the sheet. Any other callback, a Google result or a magic link included, throws .callbackIncomplete without being exchanged: a magic link completes only through your app’s confirmation step (changed in 8.2.0).
  • Because the callback never reaches your app’s URL handler, an app that signs in only with signInWith* can ignore every .oauth redirect the OS delivers.
  • Available starting from SDK version 8.0.0.
Example Usage
Related Documentation