Skip to content

Search

Documentatie

Google services

Sign in with Google on Android through Credential Manager, the OAuth clients and signing keys it needs, the fallback elsewhere, and what is planned for Play.

Op deze pagina

The google module is Sign in with Google on Android 14 and later, through the system's own Credential Manager. It needs no Google library in the game. Play Games, saved games and Play Billing are planned, not built.

Sign in with Google

pub async fn google_token() -> str {
    let answer = await task::wait(google::sign_in());
    if answer["kind"].text() == google::EVENT_SIGNED_IN {
        // answer["email"] and answer["name"] come with it.
        return answer["token"].text();
    }
    // unsupported, cancelled or error: open Google's page instead.
    ""
}
  • The accounts already signed in to this game come first, picked without a tap when there is one. Then every account on the device.
  • It answers signed_in with token (an id token issued for the server), email and name; cancelled; or error.
  • It answers unsupported off Android, below Android 14, with no [google] server_client_id, and on a device with no Google account.
  • Where it answers unsupported, a game signs in through Google's page instead: see Sign-in pages.

Setting it up

Sign in with Google takes two OAuth clients in one Google Cloud project: a web one, which the id token is issued for, and an Android one, which tells Google this game may ask.

  1. In Google Cloud's console, under APIs and services, set up the OAuth consent screen.

  2. Make a Web application client. Its id goes in project.toml; it is not a secret:

    [google]
    server_client_id = "1234-abcd.apps.googleusercontent.com"
    
    [android]
    application_id = "com.studio.game"
  3. Make an Android client with the package name, [android] application_id, and the SHA-1 of the certificate that signs the build.

The SHA-1 has to match the key the installed game was signed with, so one Android client is needed for each such key:

Build Signed with Where its SHA-1 is
From Forge, an APK installed directly your upload key, from the project's Android signing keytool -list -v -keystore upload.jks -alias <key>
From Google Play Play App Signing's key, which Play re-signs with Play Console, Test and release, App integrity, App signing
balaur export --sign debug the debug key keytool -list -v on that keystore

Play rewrites the certificate, so a game that signs in from Forge's APK can still fail from Play until the Play key's client exists. Nothing in the engine can check this for you.

Checking the token

The server checks the id token with Google. Gamend takes it at /api/v1/auth/google/id_token as { "id_token": … }, given:

Gamend setting Value
GAMEND_OAUTH_GOOGLE_CLIENT_ID, GAMEND_OAUTH_GOOGLE_CLIENT_SECRET the web client, which also serves Google's page
GAMEND_OAUTH_GOOGLE_WEB_CLIENT_ID only when the token's client differs from that one

Planned

From the engine's Google plan, in order:

  • Play Games — platform::sign_in, unlock, progress, submit_score and scores on Android. Until then they answer unsupported there.
  • Saved games — behind platform::cloud_read and cloud_write.
  • Play Billing — products, purchases and restore, checked by a server.
  • Play Integrity and Play Asset Delivery.

The Google module's reference lists its calls and constants.

Weet je het zeker?