BuildBaseBuildBase

Set up Sign in with Google

Put a Google button on your sign-in page. Make an OAuth client in Google Cloud, paste its two keys into BuildBase and register the redirect URL.

Sign in with Google puts a Google button on your hosted sign-in page. The person presses it, picks their Google account on Google's own screen, and comes back to your app signed in, with no password to make up. It suits almost any app: most people already have a Google account, from Gmail or from work. You make an OAuth client in Google Cloud (OAuth is the standard way one site lets another confirm who someone is), copy two keys from it into BuildBase, and copy one address from BuildBase back into Google.

Before you start

  • A Google account that can create a project in Google Cloud. It costs nothing.
  • An app in the BuildBase console, on the Settings tab of Authentication. Here it is Acme Analytics.
  • Room on your plan. Google counts toward your plan's limit of social sign-in providers, as GitHub, Microsoft, LinkedIn, Apple and a custom provider do.

What goes where

Copy thisFromPaste it into
Client IDGoogle Cloud, your OAuth clientBuildBase, Client ID
Client secretGoogle Cloud, the same OAuth clientBuildBase, Client secret
Redirect URLBuildBase, after you press CreateGoogle Cloud, Authorized redirect URIs
Sign-in page origin (later)BuildBase, once Google One Tap is onGoogle Cloud, Authorized JavaScript origins

The last row is only for Google One Tap. A Google client ID ends in .apps.googleusercontent.com, such as 123456789012-abc123def456.apps.googleusercontent.com. A client secret starts with GOCSPX-. The ID is not secret. The secret is: keep it like a password.

1. Make the OAuth client at Google

These steps are the ones the console shows under How to get your Google keys.

  1. Open the Credentials page in Google Cloud and sign in with the Google account that should own this. Choose a project at the top of the page, or make a new one, such as Acme Analytics.
  2. If Google asks you to set up its consent screen (Google Auth Platform) first, give your app's name and a support email, such as Acme Analytics and [email protected]. This is what your users see when they sign in. While Google lists the app's publishing status as Testing, only the test users you add there can sign in, so publish it before you launch.
  3. Choose Create credentials, then OAuth client ID, and choose Web application as its type. Give it any name, such as Acme Analytics sign-in.
  4. Google then shows a Client ID and a Client secret. Copy both. Keep this tab open: you come back to it at the end of the next part.

2. Add Google in the BuildBase console

  1. In the console, open User management, then Authentication under Access, and the Methods tab.
  2. Press Add auth method and choose Google. The dialog says what Google sign-in is for and opens How to get your Google keys, the steps above.

The Add new method dialog with Google chosen: a line on what Google sign-in is for, and the open guide How to get your Google keys with its six steps

  1. Fill in the form:
    • Title: your own name for the method, shown in the console only. The button your users see always says Google. Keep Google.
    • Client ID and Client secret: paste them from Google Cloud.
    • Google One Tap: leave it Off for now. Google One Tap explains turning it on.
    • Scopes: keep the three defaults. They ask Google for the person's email address, their name and picture, and to confirm who they are (openid). A new account is made with the email address, so never remove https://www.googleapis.com/auth/userinfo.email.

The Google form filled in: Title Google, Client ID 123456789012-abc123def456.apps.googleusercontent.com, Client secret hidden as dots, Google One Tap Off, and the three default scopes

  1. Not sure where a value is? Press the ? beside its label. Each note says what the value is, where Google shows it, and whether it is secret.

The note behind the question mark beside Client secret: what it is, where to find it on the OAuth client in Google Cloud, and to keep it private like a password

  1. Press Create. The dialog now says One step left and shows the redirect URL under Authorized redirect URIs. Press Copy.

After Create: One step left, and the Authorized redirect URIs box holding the redirect URL to paste into Google Cloud, with a copy button

  1. Press Done. Google is now in the Login methods list.
  2. Back in Google Cloud, open the same OAuth client, add the URL under Authorized redirect URIs, and press Save. Google notes that a change can take from a few minutes to a few hours to apply.

The redirect URL has this shape, with your organization's ID and the method's own ID in it:

https://api.console.buildbase.app/api/v1/auth/social/google/<orgId>/<methodId>/callback

It starts with your BuildBase server, https://api.console.buildbase.app{/* @endstat */} on BuildBase's cloud. Copy it from the console rather than typing it: Google checks it letter for letter, so a missing character or a trailing slash fails every sign-in. It never changes while the method exists. Deleting the method and adding Google again makes a new one, which you would have to register again, so edit the method instead.

The secret is never shown again. When you edit the method later, the Client secret box is empty and the line under it shows the saved secret's first and last five characters, such as Saved: GOCSP..ecret. Leave the box empty to keep it, or paste a new secret to replace it.

3. Attach it to your app

A method shows on a sign-in page only once it is ticked on an app.

  1. Open the Settings tab and press Edit on Acme Analytics.
  2. Under Methods, tick Google and press Update. The console says Client saved.

The Edit auth setting sheet for Acme Analytics, at Methods: Google ticked beside Email and password

4. Check the preview

Open the Sign-in page tab. The Preview shows your look on a sample card. Its social buttons are always GitHub and Google, whatever your app offers, so it shows where social buttons sit and how they look, not which ones you have. Two settings on the same tab, under Layout, change them: Social buttons placement (Above the form or Below the form) and Social buttons style (Buttons with names or Icons only).

To see your real page, press Open the live page for Acme Analytics above the preview. It opens in a new tab.

The Preview on the Sign-in page tab, with the button Open the live page for Acme Analytics, and a sample sign-in card whose social buttons are always GitHub and Google

5. What people see

The hosted sign-in page now has a Google button under the email and password form, after or. The register page has it too.

The hosted sign-in page Sign in to Acme, with the email and password form and, under or, a Google button

On a phone the button runs the full width of the screen:

The same sign-in page on a phone 390 pixels wide, with the Google button across the full width under the form

Pressing it opens Google's own screen, where the person picks an account and, the first time, agrees to share their name and email address with your app. Google then sends them back, and the sign-in page carries on as after any sign-in: a second step if your two-step policy asks social sign-ins for one, the Trust this device? question, and the passkey offer if your app offers passkeys. Then they are in your app.

The first sign-in

BuildBase looks for the person's account in this order:

  1. By their Google user ID. Anyone who has signed in with Google here before is found this way, even if their email address has changed since, here or at Google.
  2. By email address, when Google says the address is verified. An account with that address, made with a password or another provider, gets Google connected to it, so step 1 finds it next time.
  3. A new account, if sign-up is open to this address (see who can sign up), or the sign-in started from an invitation, and your plan has room for another user. It takes the name and email address from Google, and the address counts as verified, so no code is emailed.

Someone who signed up with Google has no password. They can make one later with Forgot password? on a client that offers email and password. Social sign-ins skip two-step sign-in unless Also ask social sign-ins is on.

In your app

Nothing changes in your code: signIn() from the SDK sends people to the hosted page, and the Google button is there. Inside your app, people see and remove their connected accounts on the SDK's Security screen, and connect Google to an account they made another way. Account security screens shows it.

import { useSaaSAuth } from '@buildbase/sdk/react';

export function SecurityButton() {
  const { openWorkspaceSettings } = useSaaSAuth();
  return (
    <button onClick={() => openWorkspaceSettings('security')}>Security</button>
  );
}

Check it works

  • Google is in the Login methods list on the Methods tab.
  • The redirect URL from the console is under Authorized redirect URIs on the same OAuth client, saved.
  • Google is ticked on your app in the Settings tab.
  • Open the live page shows the Google button.
  • Signing in with a Google account that is not yet a user creates one, and it appears under Users.
  • Signing in again with the same Google account reaches the same user.

Things to watch out for

  • Publish the consent screen before launch. While Google lists the app as Testing, only the test users you add there can sign in, up to 100 of them. Everyone else is refused on Google's page.
  • A company's Google Workspace administrator can block outside apps. Workspace lets an administrator refuse sign-in to apps they have not approved. With the default scopes your app asks only for basic profile details, which passes the setting that allows those, but not the one that blocks every outside app. Then the person's administrator has to approve your app.
  • Finish at Google within 10 minutes. A sign-in left open on Google's page for more than 10 minutes cannot finish: BuildBase sends the browser to your sign-in page, with a note that the sign-in expired. Start again from your app's Sign in button.
  • Keep the default scopes. A new account is made with the email address, so without https://www.googleapis.com/auth/userinfo.email nobody new can sign up.

If something goes wrong

What you seeWhyWhat to do
Google's page says Error 400: redirect_uri_mismatchThe redirect URL is not under Authorized redirect URIs, or differs by a characterCopy it again from the Google method in the console (press the edit button on its row) and paste it into Google Cloud. Save.
Google's page says The OAuth client was not found and Error 401: invalid_clientThe client ID in BuildBase is wrong, or the client was deleted in Google CloudCopy the client ID again from Google Cloud into the method's Client ID, and press Save.
Sign-in with that provider did not finish. Please try again.The person cancelled at Google, or Google answered with an error (provider_error)Try again. If it keeps happening, check the OAuth client in Google Cloud and its publishing status.
Sign-in with that provider failed. Please try again.Google sent the person back, but BuildBase could not finish: most often a wrong client secret (provider_failed)Make a new secret on the OAuth client and paste it into Client secret.
This email is already registered. Sign in the way you did before, then connect this provider from your account's security settings.An account has this address, and Google did not say the address is verified (email_unverified)The person signs in the way they did before, then connects Google from the Security screen.
This provider did not share an email address, so an account cannot be created. Allow access to your email address and try again.The email scope was removed (email_missing)Clear the Scopes box to go back to the defaults.
Sign-up is invite-only here, and there is no account for that address yet. Ask the team for an invitation, or sign in with an account you already have.Public sign-up is off and there is no account yet (signup_disabled)Invite the person, or open sign-up. See who can sign up.
Sign-up isn't available for this address.The address is blocked or not on your allowlist (signup_restricted)Change the lists in Who may sign up.
Join the waitlist, and you can sign up once you're approved.Sign-up is by waitlist and the address is not approved (waitlist_required)Approve them on the waitlist.
This app is not taking new sign-ups right now.Your plan's end-user limit is reached (signup_unavailable)Upgrade, or remove users you no longer need.
Your account has been blocked. Please contact support for assistance.The account is blocked (blocked)Unblock the user in the console if that was a mistake.
In the console: Your plan includes 2 social sign-in providers. Upgrade for more, or remove one.Your plan's social provider limit is reached; the number is your plan'sUpgrade, or delete a provider you no longer use.

This is what the sign-in page shows when someone cancels at Google:

The sign-in page back from Google with the message Sign-in with that provider did not finish. Please try again. above the form, which is still there to try again

The form stays under the message, so the person can try again or sign in another way.

Next steps