AnnouncementsIntroducing Arkoren

    Menu

    Native Login

    Log in mobile apps that sign in with the Google or Apple SDK by verifying their ID token against a one-time nonce.

    What's on this page
    1. Mount the nonce and native routes and follow the two-step exchange between the app and your server.
    2. List the audiences your apps request tokens for, for Google and for Apple.
    3. Know how email, the nonce and the outcome behave and which presets support native login.
    On this page

    A mobile app that signs in with the provider’s own SDK (Credential Manager or Google Sign-In, Sign in with Apple) receives an ID token and no authorization code, so it cannot use the browser callback. Only the Google and Apple presets support native login; every other preset returns ErrUnsupported. The examples assume the started client, guard and mapper from Browser Login.

    Mount Routes

    Native login uses two routes on the same session, which the app keeps in its cookie jar. Both use the default session of the session middleware. Mount them behind the same rate limit as your other login routes:

    web.Get("/auth/google/nonce", client.NonceHandler(), oauthauth.NonceOperation)
    web.Post("/auth/google/native", client.NativeHandler(guard, mapIdentity), oauthauth.NativeOperation)

    NonceHandler answers {"nonce": "..."} and stores the nonce in the session. The nonce is valid for ten minutes and one attempt spends it. The app gives the nonce to the SDK, then posts {"id_token": "..."} to NativeHandler. That handler verifies the token’s signature, expiry, issuer, audience and nonce, calls your mapper and guard.Begin, and answers like every other login method: 204 when the person is logged in, or 202 with the second-factor methods to choose from (Hold a Login). The session ID rotates, and a completed login publishes LoginSucceeded. Native login needs no challenge URL, because the 202 response carries the methods.

    What the app passes to the SDK depends on the provider. Google returns the nonce unchanged in the token’s nonce claim, so the app passes it as received. Apple puts the request nonce into the token unchanged, and this client requires the lowercase hexadecimal SHA-256 of the issued nonce, so the token never carries the secret held in the session; any other form is rejected.

    A failed attempt, including a wrong audience, costs the app a new nonce request. A missing, expired or used nonce, a bad token or a nonce mismatch returns ErrInvalidCallback and publishes LoginFailed. A malformed body or an empty id_token returns ErrInvalidLoginRequest without spending the nonce.

    Accept Audiences

    An audience names a token’s intended recipient. List the audiences your apps request tokens for with ClientBuilder.NativeAudiences. Without them the handlers return ErrNoNativeAudiences, and a token for any other audience, including the browser client ID, is rejected:

    client, err := oauth.New(oauth.Google(), cipher, webClientID,
    	func(login *oauth.ClientBuilder) {
    		login.NativeAudiences(webClientID, iosClientID)
    	},
    )
    • Google. The ID token’s audience is the server client ID the app configures in its SDK: Credential Manager’s setServerClientId on Android and GIDConfiguration.serverClientID on iOS. That is normally the web client ID, the one you give oauth.New. List it, and any iOS or Android client ID your apps request tokens for.
    • Apple. The aud is the app’s client_id, which for a native app is its bundle ID, not the Services ID of browser login. Apple’s token carries no name: the SDK hands it to the app on the first authorization only, so the app sends it to your API itself.

    Email and EmailVerified follow the browser rules: Google’s boolean email_verified and Apple’s email_verified (a boolean or "true"). A native login sets no Claims["scope"], because no authorization code is exchanged. These facts come from the provider documentation:

    Native ID tokens are not accepted by Verify, which requires API audiences and rejects tokens that carry a nonce. To trade a native login for a device token, check guard.RecentLogin first.

    For all functions and options, see the oauthauth API reference.

    Open a bulk documentation archive?

    This file contains every guide in its scope, not API declarations. Loading it all into an agent can exhaust its context window and increase processing time and cost. For coding tasks, start with the index and read only the relevant pages.

    Use the full archive for offline indexing, bulk processing, or deliberate large-context use.

    Browse the index instead
    Open archive