TwinrDocs
Native features and APIs / Google Sign-In

Google Sign-In

Let customers sign in with the Google account already on their phone, in one tap.

Google Sign-In lets customers sign in with the Google account already on their phone. They tap, pick an account, and they are in — no password to remember, no form to fill in on a small screen.

Inside the app it uses the phone's own native sign-in, so it looks and feels like every other app they use.

Twinr does not add a sign-in button to your app. Your website's own "Sign in with Google" button calls Twinr, which opens the native picker and hands the result back to you.

If you turn this on and expect a button to appear, nothing will happen. The website change in Step 4 is what makes it work.

How it fits together

  1. A customer taps your site's Google sign-in button inside the app.
  2. Your page calls twinr_google_sign_in().
  3. The phone shows its native Google account picker.
  4. Google authenticates them and Twinr receives a token.
  5. Twinr sends that token to your Auth callback URL.
  6. Your server verifies it, signs the customer in, and tells the app which page to open.

Your server stays in charge of sessions throughout. Twinr delivers a verified token; what counts as being signed in remains yours.

What you will need

RequirementNotes
A Google Cloud accountWith admin access to the project.
Your iOS bundle ID and Android package nameTwinr shows both on the Google Sign-In screen, with a copy button.
Your Android SHA-1 certificate fingerprintSee Find your SHA-1 fingerprint.
Access to your website's codeBoth the sign-in button and a server endpoint.

Step 1: Turn it on

Open Integrations → Native Features → Google Sign-In and switch on Enable Google Sign-In.

The Google Sign-In screen with its enable toggle

The settings below stay hidden until it is on.


Step 2: Choose how the token reaches you

Send token via offers two options.

OptionWhat happens
Webhook (POST JSON)Twinr POSTs the token to your Auth callback URL as JSON.
URL redirect (query parameters)The customer is redirected to your Redirect URL with the data in the query string.

Choose Webhook if your server verifies tokens before creating a session — it keeps the token off the customer's screen and out of their browser history. Choose URL redirect if your existing web sign-in already works that way.

Enter the matching URL. It must be HTTPS and publicly reachable.


Step 3: Create your Google OAuth client IDs

Google only signs a customer in when the request comes from an app it recognises. You tell Google about your app by creating OAuth client IDs in the Google Cloud Console — one per platform — then pasting them into Twinr.

Already use Google Sign-In on your website? Use that same Google Cloud project and skip ahead to Create the client IDs. Your web client ID is probably already there.

Create a Google Cloud project

  1. Open the console

    Sign in to the Google Cloud Console.

  2. Create the project

    Click New Project, enter a Project name such as MyStore Sign-In, and click Create.

This is the screen customers see when they pick an account.

  1. Open the consent screen settings

    Go to APIs & Services → OAuth consent screen.

    The Google Cloud Console navigation menu with APIs & Services expanded and OAuth consent screen highlighted
  2. Fill in your app information

    Open Branding and complete App information.

    The Branding page showing App name and User support email fields
    FieldWhat to enter
    App nameThe name customers see on the consent screen.
    User support emailAn address customers can contact.
    App logoOptional. Uploading one requires verification unless the app is internal or in testing.
  3. Finish and save

    Add your Developer contact information, accept the Google API Services: User Data Policy, and click Save and Continue.

Using Firebase as well? Set a support email in Firebase Console → Project settings → General → Public settings → Support email too. Without it, sign-in fails.

Create the client IDs

Create one client per platform. For each, go to APIs & Services → Credentials → Create credentials → OAuth client ID.

The Credentials page with the Create credentials menu open and OAuth client ID highlighted
The Create OAuth client ID form with Application type set to iOS and the Bundle ID field filled in
  1. Set the application type

    Choose iOS.

  2. Name the client

    Enter a Name such as MyStore iOS. It is only shown inside the console.

  3. Enter your bundle ID

    In Bundle ID, paste the iOS bundle ID copied from Twinr.

    Leave App Store ID and Team ID empty.

  4. Create and copy

    Click Create, then copy the Client ID.

Find your SHA-1 fingerprint

Which fingerprint you need depends on how customers get the app.

With Play App Signing — the default for new apps — Google re-signs your app before customers download it. Use Google's key, not the one in Twinr.

  1. Open App integrity

    In Google Play Console, go to your app → Test and release → Setup → App integrity.

  2. Open the App signing tab

    Select App signing.

  3. Copy the fingerprint

    Under App signing key certificate, copy the SHA-1 certificate fingerprint.

Need both? If customers get the app from Google Play and you also test builds signed by Twinr, create two Android clients with the same package name — one per fingerprint. Put the Google Play one in Twinr.

Paste the IDs into Twinr

Back on the Google Sign-In screen, fill in Google OAuth client IDs.

Twinr fieldPaste
Web client ID (optional)The Web application client ID
iOS client IDThe iOS client ID
Android client IDYour production Android client ID

Every client ID ends in .apps.googleusercontent.com.

Click Save as draft.

Google Sign-In does not use the Firebase config files. google-services.json and GoogleService-Info.plist are for push notifications and Firebase Analytics — see Firebase Setup. Google Sign-In needs the three OAuth client IDs above, and nothing else.

Both come from Google, which is why they are easily confused. Uploading a config file will not switch Google Sign-In on, and these client IDs will not enable push.


Step 4: Connect your website

Your website needs two changes: your sign-in button calls Twinr, and your server handles the token Twinr sends back.

Why not use your existing Google sign-in? Google blocks its sign-in page inside apps that show websites (Error 403: disallowed_useragent). Inside the app, the phone's native picker is the only way in — which is why your button has to call Twinr.

Call Twinr from your sign-in button

When Google Sign-In is enabled, the app adds twinr_google_sign_in() to every page it opens. It exists only inside your app with this feature on — not in a normal browser. Check for it, and fall back to your usual web sign-in:

JAVASCRIPT
function handleGoogleSignIn() {
  if (typeof twinr_google_sign_in === 'function') {
    twinr_google_sign_in();   // inside the app: native account picker
  } else {
    runWebGoogleSignIn();     // in a browser: your existing Google sign-in
  }
}

Wire your existing Google button to handleGoogleSignIn().

Receive the token by webhook

With Send token via set to Webhook (POST JSON), the app sends a POST to your Auth callback URL after every attempt:

HTTP
POST /auth/google
Content-Type: application/json
Cookie: <the cookies your site set in the app>

{
  "id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6...",
  "platform": "android",
  "success": true,
  "user_info": null
}
FieldWhat it holds
id_tokenThe Google ID token (a JWT). null when success is false.
platformios or android.
successtrue when the customer signed in and Google returned a token.
user_infoA username or buyer ID the app already knows for this customer, if any. Usually null — identify the customer from the token, not this.
error_messageSent only when success is false. cancelled means the customer closed the picker; anything else is the failure reason.

The Cookie header carries your site's cookies from the app, so you can match the sign-in to an existing visitor — a guest cart, for example.

Reply with HTTP 200 and the page to open:

JSON
{ "load_url": "https://your-domain.com/auth/google/complete?ticket=8f3c2a..." }
Your replyWhat the customer sees
200 with load_urlThe app opens load_url.
200 without load_urlNothing changes. The page stays where it was.
Any other status, or no responseA Sign In Failed message.

When sign-in fails on the phone, the app still calls your webhook with success: false and shows Sign In Failed itself. If the customer cancelled, it shows nothing. Reply 200 to these calls.

You cannot sign the customer in from the webhook reply. The app calls your webhook directly, not through the page the customer is looking at, so a Set-Cookie header in the reply never reaches their session.

Instead, make load_url a one-time sign-in link. When the app opens it, your site checks the ticket, sets the session cookie, and redirects to the customer's account. Make each ticket single-use and expire it after a minute or two.

Verify the token on your server

Never sign anyone in from a token you have not verified. Use Google's library for your language — it checks the signature, issuer and expiry for you.

CheckWhat to do
Audience (aud)Accept the client IDs you entered in Twinr. With a Web client ID set, tokens from both platforms carry that ID; without one, iPhone tokens carry your iOS client ID.
Customer IDIdentify the customer by the token's sub field. An email address can change; sub never does.
EmailTrust email only when email_verified is true.

Receive the token by URL redirect

With Send token via set to URL redirect (query parameters), the app opens your Redirect URL with the result in the query string. Any parameters already in your URL are kept.

Code
https://your-domain.com/auth/google/callback?platform=ios&success=true&id_token=eyJhbGciOi...
  • On success — success=true and id_token are present. Verify the token as above, then set the session cookie in your response. The page opens in the app's browser, so cookies work here.
  • On cancel or failure — success=false and no id_token. The reason is not sent in this mode. Show your sign-in page again.

The token appears in the page address in this mode. After signing the customer in, redirect to a clean URL so it does not linger in their history or your server logs.

Optional page callbacks

The app tells the page that called twinr_google_sign_in() how the attempt ended, so you can update the button. These run before the token is sent to your server.

JAVASCRIPT
window.onGoogleSignInResult = function (idToken) {
  // signed in: show a loading state while your server finishes
};

window.onGoogleSignInCancelled = function () {
  // the customer closed the account picker: reset the button
};

window.onGoogleSignInError = function (message) {
  // sign-in failed: reset the button
  console.error('Google Sign-In error:', message);
};

Handle the cancelled case. Customers often open the picker and change their minds, and a button left spinning looks broken.

Use these callbacks for the interface only. Do not sign the customer in from the idToken they receive — your server must verify it first. With URL redirect, the app leaves the page immediately, so the callbacks have little time to run.


Troubleshooting

ProblemWhere to look
Nothing happens when the button is tappedtwinr_google_sign_in is undefined. Check that Google Sign-In is enabled, that the installed app is a build made after you enabled it, and that your button calls handleGoogleSignIn().
The account picker does not appear on AndroidMost often the SHA-1 on your Android OAuth client does not match the key that signed this build. Builds from Google Play use the Play app signing key; builds signed by Twinr use your Twinr keystore. Also check the device has Google Play Services and a Google account signed in.
Authentication failsA client ID in Twinr does not match Google Cloud Console, or the bundle ID or package name there differs from the one Twinr shows.
Sign In Failed appears after picking an accountYour webhook did not reply with HTTP 200. Check it received the POST and did not reject the token — a wrong aud in your verification is the usual cause.
Your server signs the customer in, but the app still shows them signed outYou set the session cookie in the webhook reply, which the app never sees. Return a one-time sign-in link as load_url instead.
Your callback is never calledThe URL must be HTTPS, publicly reachable, and must match the Send token via option you chose.
Works in a browser, not in the appThe installed app predates the feature. Customers need a build made after you enabled it.