Management API Reference

Native Login With Google

React Native Google Login

Unlike the OAuth flow which requires the use of a web browser, the native Sign in with Google flow on Android uses the operating system's built-in functionalities to prompt the user for consent. Note that native sign-in has been rebranded as One Tap sign-in on Android by Google, which you should not confuse with One Tap sign in for web, as mentioned below.

When the user provides consent, Google issues an identity token (commonly abbreviated as ID token) that is then sent to your project's Openfort Auth server. When valid, a new user session is started by issuing an access and refresh token from Openfort Auth.

By default, Openfort Auth implements nonce validation during the authentication flow. This can be disabled in production under Authentication > Providers > Google > Skip Nonce Check in the Dashboard, or when developing locally by setting auth.external.<provider>.skip_nonce_check. Only disable this if your client libraries cannot properly handle nonce verification.

Make sure you have configured your Google credentials in the Openfort dashboard. Follow the configuration steps.

When working with Expo, you can use the react-native-google-signin/google-signin library library to obtain an ID token that you can pass to openfort-js authenticateThirdParty method.

Follow the Expo installation docs for installation and configuration instructions. See the openfort-js reference for instructions on initializing the openfort-js client in React Native.

./components/Auth.native.tsx

_46
import {
_46
GoogleSignin,
_46
GoogleSigninButton,
_46
statusCodes,
_46
} from '@react-native-google-signin/google-signin'
_46
// the initialized instance of openfort-js client
_46
import { openfort } from '../utils/openfort'
_46
_46
export default function () {
_46
GoogleSignin.configure({
_46
scopes: ['https://www.googleapis.com/auth/drive.readonly'],
_46
webClientId: 'YOUR CLIENT ID FROM GOOGLE CONSOLE',
_46
})
_46
_46
return (
_46
<GoogleSigninButton
_46
size={GoogleSigninButton.Size.Wide}
_46
color={GoogleSigninButton.Color.Dark}
_46
onPress={async () => {
_46
try {
_46
await GoogleSignin.hasPlayServices()
_46
const userInfo = await GoogleSignin.signIn()
_46
if (userInfo.data.idToken) {
_46
const { data, error } = await openfort.loginWithIdToken({
_46
provider: OAuthProvider.GOOGLE,
_46
token: userInfo.data.idToken,
_46
})
_46
console.log(error, data)
_46
} else {
_46
throw new Error('no ID token present!')
_46
}
_46
} catch (error: any) {
_46
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
_46
// user cancelled the login flow
_46
} else if (error.code === statusCodes.IN_PROGRESS) {
_46
// operation (e.g. sign in) is in progress already
_46
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
_46
// play services not available or outdated
_46
} else {
_46
// some other error happened
_46
}
_46
}
_46
}}
_46
/>
_46
)
_46
}