@crown-dev-studios/google-auth
v0.4.0
Published
React Native Google sign-in that returns a one-time server `authCode` instead of doing token exchange on-device. Use this when your backend owns Google OAuth and your mobile app only needs to start the flow and hand the code to your server.
Readme
@crown-dev-studios/google-auth
React Native Google sign-in that returns a one-time server authCode instead of
doing token exchange on-device. Use this when your backend owns Google OAuth and
your mobile app only needs to start the flow and hand the code to your server.
What It Includes
- Native Google auth-code sign-in for iOS and Android
- Scope management helpers for incremental consent flows
- Expo config plugin for wiring the native setup in prebuilt apps
- A small JS API surface with no opinion about your backend
Install
npm install @crown-dev-studios/google-authPeer dependency:
npm install react-nativeIf you are using Expo, use a custom dev client or a prebuilt app. Expo Go is not supported because this package ships native code.
Quick Start
import {
configureGoogleAuth,
signInWithGoogle,
} from '@crown-dev-studios/google-auth'
await configureGoogleAuth({
iosClientId: 'your-ios-client-id.apps.googleusercontent.com',
webClientId: 'your-web-client-id.apps.googleusercontent.com',
scopes: ['openid', 'email', 'profile'],
})
const { authCode, grantedScopes } = await signInWithGoogle()
// Send authCode to your server for exchange.API
configureGoogleAuth(config)
Configures the native Google SDKs.
await configureGoogleAuth({
iosClientId: 'ios-client-id',
webClientId: 'web-client-id',
scopes: ['openid', 'email', 'profile'],
})Notes:
webClientIdis always required.iosClientIdis required on iOS.- If
scopesis omitted, the default is['openid', 'email', 'profile'].
signInWithGoogle()
Starts Google sign-in and resolves to:
type GoogleAuthResult = {
authCode: string
grantedScopes: string[]
}updateGoogleScopes(request)
Requests additional scopes or replaces the previously granted set.
import { updateGoogleScopes } from '@crown-dev-studios/google-auth'
await updateGoogleScopes({
scopes: ['https://www.googleapis.com/auth/calendar.readonly'],
mode: 'add',
})mode:
'add'adds new scopes to the current session'replace'replaces the current set
getGoogleGrantedScopes()
Returns the scopes currently known to be granted for the active session.
revokeGoogleAccess()
Disconnects the app from the Google account and revokes the granted access.
signOutGoogle()
Signs out locally without necessarily revoking previously granted access.
Expo Config Plugin
Add the plugin in app.config.ts or app.json:
export default {
plugins: [
[
'@crown-dev-studios/google-auth/plugin',
{
iosClientId: 'your-ios-client-id.apps.googleusercontent.com',
webClientId: 'your-web-client-id.apps.googleusercontent.com',
},
],
],
}The plugin requires both iosClientId and webClientId. If either is missing,
native Google Sign-In configuration is skipped.
Typical Use Case
- Configure the package at app startup.
- Call
signInWithGoogle(). - Post the returned
authCodeto your backend. - Exchange the code server-side and continue your auth flow.
This package intentionally does not store access tokens or refresh tokens for you.
