PortalAuth method. Exchanges the grant of a loginWithGoogle() / loginWithApple() redirect. Pass the .oauth value parseRedirect returned. signInWithGoogle and signInWithApple do all of this for you.
The grant is exchanged only with the code verifier of the sign-in this device started, so you can pass every .oauth redirect your app receives: one this device did not start signs nobody in. See Google and Apple sign-ins are bound to the device.
Parameters
redirect: TheAuthRedirect.OAuthfromparseRedirect.redirect.provideris.googleor.apple. OnlyparseRedirectcan build one, and its grant token is not public.
AuthResult: One of:.authenticated(AuthenticatedResult): The sign-in is complete.sessionis already saved to the Keychain; pass it toPortal(credentials:)..totpRequired(TotpRequiredResult): A two-factor code is required. Nothing is persisted; complete the sign-in withverifyTotp.
PortalAuthError.oauthFlowNotStarted: This device has no Google or Apple sign-in in progress for the redirect: none was started here, it already completed and is no longer remembered (an earlier launch, another instance, or afterclearPersistedSession()), it is more than 15 minutes old, orclearPersistedSession()cancelled it. Raised before any network call, except whenclearPersistedSession()on the same instance cancels the exchange while it runs (the grant may then be spent). Not retryable with the same redirect; start a new sign-in.PortalRequestsError.unauthorized: Portal refused the grant: it was already used, has expired, was issued for another environment, or its sign-in method has since been disabled — or it belongs to a sign-in other than the one in progress on this device, for example one a newer sign-in replaced. Also raised without a request when the remembered session has since ended. NotPortalAuthError.grantRejected, which is only for magic links. Start a new sign-in.PortalAuthError.invalidGrantResponse: The exchange returned neither a session token nor auserJwt.PortalAuthError.malformedResponse(path:missing:): The response did not carry the documented fields.PortalAuthError.sessionStorageFailure(message:): The Keychain failed this time. Either the sign-in in progress could not be read, in which case nothing was sent, or the grant was exchanged but the session could not be saved, in which case it is not returned. In both cases callcompleteOAuthLoginagain with the same redirect on the same instance: the first retries the exchange, the second finishes the write without sending the grant again.- Other transport errors unchanged.
CancellationError: The calling task was already cancelled. Nothing is sent.
- Bound to this device. Only the sign-in this device started can complete: one at a time per auth environment, within 15 minutes, in this app. A sign-in started with
loginWithGoogle()/loginWithApple()still completes if iOS terminated your app while the browser was open. Available starting from SDK version 8.2.0. - Exchanged successfully at most once per instance, on the same terms as
confirmMagicLink: concurrent calls with the same redirect run one at a time, so they share one successful exchange; a call after a successful one returns the remembered result — the samePortalSessioninstance — without a request, while that session is live; only the most recent sign-in is remembered, on this instance and in this process. - A failed exchange is not remembered, so calling again sends the grant again; after a dropped connection or an HTTP error, the sign-in stays in progress for that retry. That succeeds only if the failed attempt never reached Portal; otherwise it throws
PortalRequestsError.unauthorized. The exception is.sessionStorageFailureafter the exchange, above. After.invalidGrantResponseor.malformedResponsethe grant is spent, so a retry throwsoauthFlowNotStarted. - A Google or Apple sign-in must finish at the provider within 10 minutes and be exchanged within 15 minutes of starting. See Grants are single use.
- After the app is relaunched, a redirect delivered again for a completed sign-in fails, usually with
oauthFlowNotStarted. Restore the session withrestoreSessioninstead. - On success the session is persisted before it is returned.
- Cancellation is honoured only before the exchange starts; once it has started it runs to completion and the result is still returned and remembered. A
clearPersistedSession()on the same instance cancels it instead: it throwsoauthFlowNotStartedrather than return a session the clear is about to delete. One running on another instance completes, so if your app signed out while it ran, discard the result instead of adopting it. - Anything you do with the result has to be safe to run twice, because a repeat call returns the same result.
- Available starting from SDK version 8.2.0.