Skip to main content
Class Definition
PortalAuth drives Portal’s Client Auth APIs and resolves a PortalSession that you pass to Portal(credentials:). It shares no state with Portal: it never touches wallets, MPC or signing, and your app owns all UI, redirect forwarding and wallet creation. Initializer
Parameters
  • authEnvironmentId: The Auth Environment ID from Authentication > Configure in the Portal dashboard. Sent as the x-portal-auth-environment-id header on every request, and used as the Keychain key for the persisted session and the Google or Apple sign-in in progress, so two instances built with the same ID share both.
  • redirectUrl: Where Portal sends the user once a magic link or provider sign-in completes. Must appear byte-for-byte on the environment’s Redirect URLs allow list and must match the URL scheme (or Universal Link) your app registers. signInWithGoogle / signInWithApple additionally require a custom scheme such as myapp://auth/callback.
  • apiHost: Optional Portal API host override. localhost and 127.0.0.1 use http://.
  • magicLink: The fromEmail and templateId that sendMagicLink requires. Omit it in an OAuth-only app.
  • isAccountAbstracted: Whether the client Portal creates for a first-time user uses gas sponsorship. Omitted from every request when nil. Only takes effect on a user’s first sign-in.
Throws
  • PortalAuthError.invalidArgument(name:): authEnvironmentId or redirectUrl is empty or blank. The initializer performs no network or Keychain I/O.
Properties and configuration
  • prefersEphemeralWebBrowserSession: Bool: When true, signInWith* opens a browser sheet that does not share Safari’s cookies, so an existing Google or Apple sign-in is not reused. Defaults to false. Set it to true to let a user who signed out pick a different account.
  • setAuthPresentationAnchor(_ anchor: ASPresentationAnchor): The window signInWith* presents the browser sheet from. Held weakly. Required before calling signInWithGoogle or signInWithApple.
Methods Types
AuthRedirect is what parseRedirect returns. Only parseRedirect can build a .magicLink or .oauth value, the grant token of an OAuth is not public, and printing an AuthRedirect shows <redacted> in place of its token. MagicLinkDetails.email is the full address a magic link signs in to: show it on your confirmation screen, never log it. Printing a MagicLinkDetails shows <redacted> in place of the email; read email to display it. PortalSession is a PortalCredentials: getToken() returns the Client Session Token until the session is invalidated, then throws PortalCredentialError.sessionInvalidated; invalidate() clears the in-memory token and deletes the persisted copy. endUserId is never secret and is the identifier to log and to key per-user state on. Errors PortalAuthError covers the authentication flow itself: PortalAuthSignInError is specific to signInWithGoogle / signInWithApple. Its raw values are the Web SDK’s popup codes: closed (POPUP_CLOSED), unavailable (POPUP_UNAVAILABLE), signInInProgress (SIGN_IN_ALREADY_IN_PROGRESS) and callbackIncomplete (CALLBACK_INCOMPLETE). Apart from rateLimited and accountAbstractionUnavailable, transport failures are not remapped, with one more exception: a 401 from getMagicLinkDetails or confirmMagicLink surfaces as PortalAuthError.grantRejected. Any other 401 from a PortalAuth call surfaces as PortalRequestsError.unauthorized, unchanged, including a Google or Apple grant Portal refuses, for example one from a sign-in other than the one in progress on this device; see Handle errors for what it means on each call. PortalAuthError gained grantRejected and oauthFlowNotStarted in 8.2.0, so an exhaustive switch over it needs a case for each. Notes
  • Hold one long-lived instance. confirmMagicLink, completeOAuthLogin and signInWith* remember the last grant they exchanged so a redirect delivered twice resolves to the same result while the session is live; that memory lives on the instance, in this process.
  • A magic link completes in two steps: getMagicLinkDetails, your own confirmation screen, then confirmMagicLink. The SDK provides no UI for this. A Google or Apple redirect needs no check of your own: pass every .oauth result to completeOAuthLogin.
  • The persisted session is stored in the Keychain with kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly, keyed by authEnvironmentId, in a namespace separate from wallet shares. It never syncs through iCloud Keychain, and it survives app deletion.
  • Google and Apple sign-ins are bound to the device with a PKCE code verifier kept in the Keychain the same way, one per auth environment (the last one stored wins); a sign-in can be completed for 15 minutes. Available starting from SDK version 8.2.0; see Google and Apple sign-ins are bound to the device.
  • Available starting from SDK version 8.0.0. parseRedirect, getMagicLinkDetails, confirmMagicLink and completeOAuthLogin require 8.2.0.
Example Usage
Related Documentation