Provides Google authentication integration for Exponent apps, using either the native Google Sign In SDK (only in standalone apps) or a system web browser (not WebView, so credentials saved on the device can be re-used!).
Once you have the token, if you would like to make further calls to the Google API, you can use Google’s REST APIs directly through HTTP (using fetch, for example).
// Example of using the Google REST API
async function getUserInfo(accessToken) {
let userInfoResponse = await fetch('https://www.googleapis.com/userinfo/v2/me', {
headers: { Authorization: `Bearer ${accessToken}`},
});
return userInfoResponse;
}
Exponent.Google.logInAsync(options)
Prompts the user to log into Google and grants your app permission to access some of their Google data, as specified by the scopes.
A map of options:
behavior (string) — The type of behavior to use for login, either web
or system
. Native (system
) can only be used inside of a standalone app when built using the steps described below. Default is web
inside of Exponent app, and system
in standalone. The only case where you would need to change this is if you would prefer to use web
inside of a standalone app.
scopes (array) — An array specifying the scopes to ask for from Google for this login (more information here). Default scopes are ['profile', 'email']
.
androidClientId (string) — The Android client id registered with Google for use in the Exponent client app.
iosClientId (string) — The iOS client id registered with Google for use in the Exponent client app.
androidStandaloneAppClientId (string) — The Android client id registered with Google for use in a standalone app.
iosStandaloneAppClientId (string) — The iOS client id registered with Google for use in a standalone app.
returns
If the user or Google cancelled the login, returns { type: 'cancel' }
.
Otherwise, returns { type: 'success', accessToken, user: {...profileInformation} }
. accessToken
is a string giving the access token to use with Google HTTP API requests.
In the Exponent client app, you can only use browser-based login (this works very well actually because it re-uses credentials saved in your system browser). If you build a standalone app, you can use the native login for the platform.
To use Google Sign In, you will need to create a project on the Google Developer Console and create an OAuth 2.0 client ID. This is, unfortunately, super annoying to do and we wish there was a way we could automate this for you, but at the moment the Google Developer Console does not expose an API. You also need to register a separate set of Client IDs for a standalone app, the process for this is described later in this document.
Get an app set up on the Google Developer Console
Create an iOS OAuth Client ID
host.exp.exponent
as the bundle identifier.iosClientId
option for Exponent.Google.loginAsync
(see code example below).Create an Android OAuth Client ID
openssl rand -base64 32 | openssl sha1 -c
in your terminal, it will output a string that looks like A1:B2:C3
but longer. Copy the output to your clipboard.host.exp.exponent
as the “Package name”.androidClientId
option for Exponent.Google.loginAsync
(see code example below).Add the Client IDs to your app
import Exponent from 'exponent';
async function signInWithGoogleAsync() {
try {
const result = await Exponent.Google.logInAsync({
androidClientId: YOUR_CLIENT_ID_HERE,
iosClientId: YOUR_CLIENT_ID_HERE,
scopes: ['profile', 'email'],
});
if (result.type === 'success') {
return result.accessToken;
} else {
return {cancelled: true};
}
} catch(e) {
return {error: true};
}
}
If you want to use Google Sign In for a standalone app, you can follow these steps. These steps assume that you already have it working on the Exponent client app. If you have already created an API key for Google Maps, you skip steps 3 through 8, inclusive.
Get a Google API Key for your app (skip this if you already have one, eg: for Google Maps)
android.package
from exp.json
(eg: ca.brentvatne.growlerprowler
) to the Package name field.keytool -list -printcert -jarfile growler.apk | grep SHA1 | awk '{ print $2 }'
(where growler.apk
is the name of the apk produced in step 1).Get an OAuth client ID for your app
keytool -list -printcert -jarfile growler.apk | grep SHA1 | awk '{ print $2 }'
(where growler.apk
is the name of the apk produced in step 1).android.package
from exp.json
(eg: ca.brentvatne.growlerprowler
) to the Package name field.Add the configuration to your app
exp.json
and add your Google API Key to android.config.googleSignIn.apiKey
.keytool -list -printcert -jarfile growler.apk | grep SHA1 | awk '{ print $2 }' | sed -e 's/\://g'
(where growler.apk
is the name of the apk produced in step 1).exp.json
under android.config.googleSignIn.certificateHash
.Exponent.Google.logInAsync(..)
, pass in the OAuth client ID as the androidStandaloneAppClientId
option.If you want to use native sign in for a standalone app, you can follow these steps. These steps assume that you already have it working on the Exponent client app.
bundleIdentifier
to your exp.json
if you don’t already have one.bundleIdentifier
in the Bundle ID field, then press Create.exp.json
under ios.config.googleSignIn.reservedClientId
.Exponent.Google.logInAsync
, provide the OAuth client ID as the iosStandaloneAppClientId
option.© Copyright 2025, Exponent. Created using Gatsby.