Google Sign-In JS Bridge

Last updated: Oct 28, 2026

The Google Sign-In bridge lets your website open the native Google account picker on the device and receive the signed-in user's profile and a Google ID token back. Your backend verifies that token to log the user in. It works the same way on Android and iOS.

The app does not take over your website's Google login automatically — inside the app, your "Sign in with Google" button must trigger this bridge.

For a general introduction to the JavaScript Bridge, see the Overview article.

Prerequisites

Before the bridge can trigger Google Sign-In, configure the Google Sign-In module in your Appilix dashboard:

  1. Go to your app's Integration Modules and enable Google Sign-In.
  2. Enter the Android Client ID and/or iOS Client ID generated in Google Cloud Console for your app.
  3. Enter the Web App Client ID — your website's Web application OAuth Client ID from the same Google Cloud project.
  4. Rebuild your app so the new settings are included.

See the Google Sign-In article for how to create these Client IDs.

How It Works

  1. The user taps your website's "Sign in with Google" button inside the app.
  2. Your website sends a google_sign_in message to the app via the bridge.
  3. The app opens the native Google account picker and the user selects an account.
  4. The app sends the user's profile and ID token back to your website.
  5. Your website sends the ID token to its backend, which verifies it and logs the user in.

Triggering Sign-In

javascript
appilix.postMessage(JSON.stringify({
    type: "google_sign_in",
    props: {
        response_type: "code"
    }
}));

props is optional — { type: "google_sign_in" } on its own is a valid request.

Parameters

ParameterRequiredDescription
response_typeNoSet to "code" to also receive a server auth code your backend can exchange for Google access tokens. Leave it out if the ID token is enough to log the user in

The Web App Client ID and scopes always come from the Google Sign-In module settings and cannot be set from the bridge. Scopes default to email profile when the Scopes field is empty.

Handling the Response

Set up the listener before triggering sign-in:

javascript
appilix.onmessage = function(event) {
    const data = JSON.parse(event.data);

    if (!data || data.type !== "google_sign_in") return;

    if (!data.response.error) {
        // Send the ID token to your backend to verify it and log the user in
        fetch("/auth/google/app", {
            method:  "POST",
            headers: { "Content-Type": "application/json" },
            body:    JSON.stringify({ id_token: data.response.id_token })
        });
    } else {
        // Sign-in failed or was cancelled
        console.log("Sign-in failed:", data.response.error);
    }

    appilix.onmessage = null;
};

Response Fields

FieldDescription
errornull on success, otherwise the reason sign-in failed (e.g. the user closed the account picker)
emailUser's Google account email address
nameUser's display name. Empty string if the account has none
pictureURL of the user's Google profile photo. Empty string if the account has none
idStable Google account ID — the same value as the sub claim in the ID token
id_tokenSigned Google ID token (JWT) issued for your Web App Client ID. Always present on success
codeServer auth code, only present when response_type is "code". Otherwise null

On failure, every field except error is null, so the response always has the same shape.

Verifying the ID Token on Your Backend

The email, name, and other fields are returned for convenience — they are not proof of identity on their own. Before logging the user in, your backend must verify id_token and check that:

  • The token's signature is valid against Google's public keys.
  • aud equals your Web App Client ID.
  • iss is accounts.google.com or https://accounts.google.com.
  • exp has not passed.

Google's official libraries perform all of these checks for you.

Node.js (google-auth-library):

javascript
const { OAuth2Client } = require("google-auth-library");

const WEB_CLIENT_ID = "YOUR_WEB_CLIENT_ID";
const client = new OAuth2Client(WEB_CLIENT_ID);

async function verifyGoogleIdToken(idToken) {
    const ticket  = await client.verifyIdToken({ idToken, audience: WEB_CLIENT_ID });
    const payload = ticket.getPayload();
    return { google_id: payload.sub, email: payload.email, name: payload.name };
}

PHP (google/apiclient):

php
$client  = new Google_Client(['client_id' => 'YOUR_WEB_CLIENT_ID']);
$payload = $client->verifyIdToken($id_token);

if ($payload) {
    $google_id = $payload['sub'];
    $email     = $payload['email'];
} else {
    // Invalid ID token — do not log the user in
}

Identify the user by sub (the same value as id) rather than by email — it never changes, while a user's email can.

Exchanging the Auth Code

Only needed when you send response_type: "code" and your backend calls Google APIs on the user's behalf. Requesting a code may show the user an extra consent screen for the configured scopes.

From your backend, send a POST request to https://oauth2.googleapis.com/token with:

ParameterValue
codeThe code from the response
client_idYour Web App Client ID
client_secretYour Web App Client Secret
grant_typeauthorization_code
redirect_uriAn empty string — the code was issued to the app, not through a browser redirect

Google responds with an access token for the requested scopes. Auth codes are single-use and expire quickly, so exchange them as soon as your backend receives them.

Complete Example

javascript
function signInWithGoogle() {
    // In a regular browser, keep your existing web Google login
    if (typeof appilix === 'undefined') {
        startWebGoogleLogin();
        return;
    }

    appilix.onmessage = function(event) {
        const data = JSON.parse(event.data);
        if (!data || data.type !== "google_sign_in") return;

        appilix.onmessage = null;

        if (data.response.error) {
            console.error("Sign-in error:", data.response.error);
            return;
        }

        // Send the ID token to your backend for verification
        fetch("/auth/google/app", {
            method:  "POST",
            headers: { "Content-Type": "application/json" },
            body:    JSON.stringify({ id_token: data.response.id_token })
        })
        .then(res => res.json())
        .then(result => {
            if (result.success) window.location.href = "/dashboard";
        });
    };

    appilix.postMessage(JSON.stringify({
        type: "google_sign_in"
    }));
}

startWebGoogleLogin() stands for whatever your website already does to sign users in with Google in a browser.

Important Notes

  • Always verify id_token on your backend. Never log a user in based on the client-side response alone.
  • If the user closes the account picker, error is set and no token is returned.
  • On Android, sign-in fails for Play Store installs until the Play App Signing SHA-1 is added to your Android Client ID — see After Publishing to Google Play.
  • Implementing this requires changing your website's sign-in button logic and adding a backend endpoint that verifies the token. Involve a developer if needed.