PortalAuth method. Fetches a fresh authorize URL, presents Google 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.sessionis aPortalSessionalready saved to the Keychain; pass it toPortal(credentials:).clientIdandisAccountAbstracteddescribe the client Portal resolved..totpRequired(TotpRequiredResult): The environment requires a two-factor code. Nothing is persisted; complete the sign-in withverifyTotp.
PortalAuthSignInError.unavailable: No presentation anchor was set (or its window was deallocated), theredirectUrlis not a custom URL scheme, or the system refused to start the session.PortalAuthSignInError.signInInProgress: AnothersignInWith*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 Google sign-in result for this instance, such as an Apple result or a magic link. Nothing is exchanged.PortalAuthError.authMethodUnavailable(.google): Google is not enabled for this auth environment.PortalAuthError.authenticationFailed(error:): The callback URL carried anerrorparameter 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 aloginWithGoogle()/loginWithApple()call (or asignInWith*call on another instance), or cancelled byclearPersistedSession(), while the sheet was open: its grant is not exchanged. Also thrown whenclearPersistedSession()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 (theredirectUrlis not allow-listed, the Auth Environment ID is wrong, or an enabled provider is missing its credentials), or rejected the grant.- Other
PortalAuthErrorcasescompleteOAuthLogincan throw, and transport errors unchanged.
- Call
setAuthPresentationAnchor(_:)with your window before signing in. The anchor is held weakly. - Requires a custom-scheme
redirectUrlsuch asmyapp://auth/callback. Anhttps://Universal Link is not supported bysignInWith*in this release and throws.unavailable; useloginWithGoogle,parseRedirectandcompleteOAuthLoginfor 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 concurrentsignInWith*call on the same instance throws.signInInProgressrather 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. - Set
prefersEphemeralWebBrowserSession = trueto open the sheet without shared cookies. The defaultfalselets a returning user reuse their Safari sign-in, which also means a user who signed out gets the same Google account back. - Cancelling the calling
Taskbefore 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 withoauthFlowNotStarted, but it cannot close the sheet. Do not adopt a result that returns after the sign-out. - Completes only a Google result from the sheet. Any other callback, an Apple result or a magic link included, throws
.callbackIncompletewithout 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.oauthredirect the OS delivers. - Available starting from SDK version 8.0.0.