Skip to main content

Types

Every type, enum and type guard exported by react-native-oauth-essentials. Import types with import type, and enums and functions with a normal import:

import { CredentialsType, CredentialError, isCredentialError } from 'react-native-oauth-essentials';
import type { GoogleIdCredentialResult, GoogleSignInOptions } from 'react-native-oauth-essentials';

The Platform column says where a property has an effect. Options that do nothing on the current platform are ignored, with a warning in development (see Development warnings).

For the error codes, their causes and how to handle them, see Errors.

GroupTypes
OptionsGoogleClientIds, GoogleClientId, GoogleSignInOptions, HybridSignInOptions, AppleSignInOptions, PasskeyOptions, OAuthSignInOptions
ResultsGoogleIdCredentialResult, PasswordCredentialResult, AppleIdCredentialResult, WebAppleIdCredentialResult, PassKeyCredentialResult, OAuthCredentialResult, CancelledCredentialResult, HybridSignInResult
EventsCredentialSuccessEvent, CredentialFailureEvent
EnumsCredentialsType, AppleIdCredentialState, CredentialError
ErrorsCredentialErrorCode, OauthEssentialsError, isCredentialError

Return type of each method​

MethodResolves
googleSignInGoogleIdCredentialResult | CancelledCredentialResult
googleSilentSignInGoogleIdCredentialResult | CancelledCredentialResult
signOutboolean (always true)
getPasswordPasswordCredentialResult | CancelledCredentialResult
passwordSignInboolean (saved or not; always false on iOS)
appleSignInAppleIdCredentialResult | WebAppleIdCredentialResult | CancelledCredentialResult
getAppleIdCredentialStateAppleIdCredentialState
hybridSignInHybridSignInResult
createPassKeyPassKeyCredentialResult | CancelledCredentialResult
getPassKeyPassKeyCredentialResult | CancelledCredentialResult
cancelPassKeyAutoFillboolean (whether a pending AutoFill request was cancelled)
oauthSignInOAuthCredentialResult | CancelledCredentialResult
addCredentialSuccessListener / addCredentialFailureListener / addAppleIdCredentialRevokedListenerEventSubscription (from react-native, call .remove())

Every result has a type field from CredentialsType, so a switch (result.type) narrows data.

Options​

GoogleClientIds​

Google OAuth client ids per platform, all from the same Google Cloud project. Taken by googleSignIn, googleSilentSignIn and hybridSignIn. Both ids are optional: a missing id is read from the app config, which the Expo plugin writes from its options or the Firebase files (see Google client ids).

type GoogleClientIds = {
iosClientId?: string;
webClientId?: string;
};
PropertyTypePlatformDescription
iosClientIdstringiOSiOS client id (created with the bundle id). When missing, iOS reads GIDClientID from Info.plist, then CLIENT_ID from the Firebase GoogleService-Info.plist. None rejects with CONFIGURATION_ERROR
webClientIdstringBothAndroid: the client id passed to Credential Manager. When missing, Android reads the com.oauthessentials.GOOGLE_WEB_CLIENT_ID meta-data of AndroidManifest.xml, then the default_web_client_id string generated by the Firebase google-services Gradle plugin. None rejects with CONFIGURATION_ERROR. iOS: the default serverClientId (idToken audience and serverAuthCode); when missing, iOS reads GIDServerClientID from Info.plist

GoogleClientId​

A GoogleClientIds object, or a single client id string. A string is used as is on both platforms, so it must be the iOS client id on iOS and the web client id on Android.

type GoogleClientId = string | GoogleClientIds;
// Ids in the app config (Expo plugin, Info.plist, AndroidManifest or Firebase files)
await googleSignIn();
await googleSignIn({ mode: 'button' });

// Ids in code
const GOOGLE_CLIENT_IDS: GoogleClientIds = {
iosClientId: '1234-abcd.apps.googleusercontent.com',
webClientId: '5678-efgh.apps.googleusercontent.com',
};
await googleSignIn(GOOGLE_CLIENT_IDS, { mode: 'button' });

GoogleSignInOptions​

Options of googleSignIn and googleSilentSignIn.

type GoogleSignInOptions = {
authorizedAccounts?: boolean;
autoSelectEnabled?: boolean;
mode?: 'bottomSheet' | 'button';
nonce?: string;
hint?: string;
hostedDomain?: string;
scopes?: string[];
offlineAccess?: boolean;
serverClientId?: string;
};
PropertyTypeDefaultPlatformDescription
authorizedAccountsbooleanfalseAndroidOnly show accounts that already signed in to the app
autoSelectEnabledbooleanfalseAndroidSign in without UI when a single authorized account is available
mode'bottomSheet' | 'button''bottomSheet'AndroidbottomSheet shows the Credential Manager sheet and, unless authorizedAccounts is set, falls back to button when no credential is available (no account, or the sheet is in cooldown after being dismissed). button always shows the "Sign in with Google" flow: use it for a button tap
noncestring-BothEmbedded as is in the idToken, so your backend can prevent replay attacks. Ignored by googleSilentSignIn on iOS
hintstring-iOSEmail to preselect in the Google page
hostedDomainstring-BothRestricts sign in to a Google Workspace domain. On Android it only applies to the button flow and to the authorization step, not to the bottom sheet
scopesstring[]-BothAdditional OAuth scopes. iOS: requested during sign in; accessToken and grantedScopes are always returned. Android: requested in a second step (Authorization API, may show a consent screen); without scopes/offlineAccess, accessToken and grantedScopes are null
offlineAccessbooleanfalseAndroidReturns a serverAuthCode your backend can exchange for a refresh token. On iOS serverAuthCode is returned whenever serverClientId is set
serverClientIdstringwebClientIdBothiOS: web (server) client id, used as the idToken audience and for serverAuthCode. Android: client id the serverAuthCode is issued for
const options: GoogleSignInOptions = {
mode: 'button',
nonce: 'random-nonce',
scopes: ['https://www.googleapis.com/auth/drive.readonly'],
};
await googleSignIn(options);

HybridSignInOptions​

Options of hybridSignIn. Same shape as GoogleSignInOptions, but only some fields are used:

type HybridSignInOptions = GoogleSignInOptions;
PropertyiOSAndroid
nonceUsed, for Apple IDUsed, for Google ID
authorizedAccounts, autoSelectEnabledIgnoredUsed, for Google ID
mode, hint, scopes, offlineAccess, hostedDomain, serverClientIdIgnoredIgnored

AppleSignInOptions​

Options of appleSignIn. iOS only: on Android put the nonce and state in your androidWebUrl.

type AppleSignInOptions = {
nonce?: string;
state?: string;
};
PropertyTypePlatformDescription
noncestringiOSPassed as is to Apple and embedded in the idToken. Firebase and Supabase expect the SHA-256 of the raw nonce here
statestringiOSOpaque value returned in AppleIdCredentialResult.data.state

PasskeyOptions​

Options of createPassKey and getPassKey.

type PasskeyOptions = {
requestJson: string;
preferImmediatelyAvailableCredentials?: boolean;
mediation?: 'modal' | 'autofill';
};
PropertyTypeDefaultPlatformDescription
requestJsonstringrequiredBothWebAuthn options JSON from your server: PublicKeyCredentialCreationOptions for createPassKey, PublicKeyCredentialRequestOptions for getPassKey
preferImmediatelyAvailableCredentialsbooleanfalseAndroidOnly offer credentials already available on the device. iOS modal requests always behave this way
mediation'modal' | 'autofill''modal'iOS 16+autofill (getPassKey only) shows passkeys in the QuickType bar of a text field with textContentType="username" instead of a sheet. See Passkeys
const options: PasskeyOptions = {
requestJson: JSON.stringify({
challenge: 'base64url-challenge',
rp: { name: 'Your App', id: 'yourapp.com' },
user: { id: 'base64url-user-id', name: 'user@example.com', displayName: 'User Name' },
pubKeyCredParams: [{ type: 'public-key', alg: -7 }],
authenticatorSelection: { userVerification: 'required' },
}),
};
await createPassKey(options);

OAuthSignInOptions​

Options of oauthSignIn.

type OAuthSignInOptions = {
authorizationEndpoint: string;
clientId: string;
redirectUri?: string;
scopes?: string[];
additionalParameters?: Record<string, string>;
tokenEndpoint?: string;
usePKCE?: boolean;
prefersEphemeralSession?: boolean;
};
PropertyTypeDefaultPlatformDescription
authorizationEndpointstringrequiredBothAuthorization url of the provider
clientIdstringrequiredBothOAuth client id
redirectUristringOAUTH_REDIRECT_URIBothWhere the provider redirects. Without a scheme it rejects with CONFIGURATION_ERROR
scopesstring[]-BothSent as scope, space separated
additionalParametersRecord<string, string>-BothExtra authorization parameters, like prompt, login_hint or nonce. They may override scope. response_type, client_id, redirect_uri, state, code_challenge and code_challenge_method are set by the library and ignored here, with a warning in development
tokenEndpointstring-BothWhen set, the code is exchanged for tokens on the device. Leave it out to exchange the code on your backend (recommended for confidential clients)
usePKCEbooleantrueBothSends a PKCE S256 code_challenge
prefersEphemeralSessionbooleanfalseiOSDo not share cookies with Safari

Results​

GoogleIdCredentialResult​

Resolved by googleSignIn, googleSilentSignIn and hybridSignIn (Android).

type GoogleIdCredentialResult = {
type: CredentialsType.GOOGLE_ID;
data: {
id: string;
idToken: string;
displayName: string;
givenName: string;
familyName: string;
email?: string;
profilePictureUri?: string | null;
phoneNumber?: string | null;
accessToken?: string | null;
serverAuthCode?: string | null;
grantedScopes?: string[] | null;
};
};
FieldTypePlatformDescription
idstringBothiOS: Google user id (the idToken sub). Android: the account email
idTokenstringBothJWT to verify on your backend
displayNamestringBothFull name
givenNamestringBothFirst name
familyNamestringBothLast name
emailstringBothAccount email
profilePictureUristring | nullBothProfile picture url. iOS: 200px url, or "" without picture
phoneNumberstring | nullAndroidPhone number, when shared
accessTokenstring | nullBothiOS: always returned. Android: only when scopes or offlineAccess were requested
grantedScopesstring[] | nullBothScopes granted to accessToken
serverAuthCodestring | nullBothAndroid: with offlineAccess. iOS: when serverClientId (or webClientId) is set, never on googleSilentSignIn

PasswordCredentialResult​

Resolved by getPassword and hybridSignIn.

type PasswordCredentialResult = {
type: CredentialsType.PASSWORD;
data: {
username: string;
password: string;
};
};
FieldTypeDescription
usernamestringSaved username or email
passwordstringSaved password

AppleIdCredentialResult​

Resolved by appleSignIn and hybridSignIn on iOS.

type AppleIdCredentialResult = {
type: CredentialsType.APPLE_ID;
data: {
idToken: string;
authorizationCode: string;
user: string;
email: string;
fullName: string;
likelyReal: boolean;
state?: string | null;
};
};
FieldTypeDescription
idTokenstringJWT to verify on your backend
authorizationCodestringShort lived code your backend can exchange with Apple
userstringStable user id for the app (same across reinstalls). Pass it to getAppleIdCredentialState
emailstringEmail, possibly a private relay address. Apple only sends it on the first authorization
fullNamestringFull name. Apple only sends it on the first authorization
likelyRealbooleanApple considers the user likely a real person
statestring | nullThe state passed in AppleSignInOptions
info

Apple only sends email and fullName the first time a user authorizes the app. appleSignIn keeps the first result of each user in memory (until the app is killed) and fills them in later results, but save them on your backend on the first sign in.

WebAppleIdCredentialResult​

Resolved by appleSignIn on Android, with the url your backend redirected to at the end of the Apple web flow.

type WebAppleIdCredentialResult = {
type: CredentialsType.WEB_APPLE_ID;
data: {
url: string;
scheme: string | null;
host: string | null;
path: string | null;
query: string | null;
};
};
FieldTypeDescription
urlstringFull redirect url
schemestring | nullUrl scheme, e.g. com.example.app
hoststring | nullUrl host, e.g. oauth
pathstring | nullUrl path, e.g. /callback
querystring | nullQuery string, with whatever your backend put there
const params = new URLSearchParams(result.data.query ?? '');
const token = params.get('token');

PassKeyCredentialResult​

Resolved by createPassKey and getPassKey.

type PassKeyCredentialResult = {
type: CredentialsType.PASSKEY;
data: string;
};
FieldTypeDescription
datastringWebAuthn response JSON to send to your server: the registration response (createPassKey) or the authentication response (getPassKey), binary fields in base64url

OAuthCredentialResult​

Resolved by oauthSignIn.

type OAuthCredentialResult = {
type: CredentialsType.OAUTH;
data: {
code: string;
state: string;
redirectUri: string;
codeVerifier: string | null;
params: Record<string, string>;
tokens: Record<string, unknown> | null;
};
};
FieldTypeDescription
codestringAuthorization code
statestringThe state generated by the library, already checked against the redirect
redirectUristringRedirect uri used in the request. Send it with the code to your backend
codeVerifierstring | nullPKCE verifier, null when usePKCE is false
paramsRecord<string, string>Every query and fragment parameter of the redirect
tokensRecord<string, unknown> | nullToken endpoint JSON response, only when tokenEndpoint is set
const result = await oauthSignIn({ authorizationEndpoint, clientId, scopes: ['openid', 'email'] });
if (result.type === CredentialsType.OAUTH) {
await api.exchangeCode(result.data.code, result.data.codeVerifier, result.data.redirectUri);
}

CancelledCredentialResult​

Resolved by every sign in method when the user dismisses the UI (and in the other cases listed per method in Methods). It is not an error: show the sign in screen again or other options.

type CancelledCredentialResult = {
type: CredentialsType.CANCELLED;
data: null;
};

HybridSignInResult​

Resolved by hybridSignIn. Apple ID only on iOS, Google ID only on Android.

type HybridSignInResult =
| AppleIdCredentialResult
| GoogleIdCredentialResult
| PasswordCredentialResult
| CancelledCredentialResult;

Events​

CredentialSuccessEvent​

Received by addCredentialSuccessListener. Same shape as the resolved result, including CANCELLED.

type CredentialSuccessEvent = {
type: string;
data: Object;
};
FieldTypeDescription
typestringA CredentialsType value
dataobject | nullThe result data (null for CANCELLED)

CredentialFailureEvent​

Received by addCredentialFailureListener. See which errors are emitted.

type CredentialFailureEvent = {
code: CredentialErrorCode;
message: string;
};
FieldTypeDescription
codeCredentialErrorCodeThe error code
messagestringNative error message

Enums​

CredentialsType​

The type of every result.

ValueResultResolved by
GOOGLE_IDGoogleIdCredentialResultgoogleSignIn, googleSilentSignIn, hybridSignIn (Android)
PASSWORDPasswordCredentialResultgetPassword, hybridSignIn
APPLE_IDAppleIdCredentialResultappleSignIn (iOS), hybridSignIn (iOS)
WEB_APPLE_IDWebAppleIdCredentialResultappleSignIn (Android)
PASSKEYPassKeyCredentialResultcreatePassKey, getPassKey
OAUTHOAuthCredentialResultoauthSignIn
CANCELLEDCancelledCredentialResultEvery sign in method
const result = await hybridSignIn();
switch (result.type) {
case CredentialsType.APPLE_ID:
await api.signInWithApple(result.data.idToken);
break;
case CredentialsType.GOOGLE_ID:
await api.signInWithGoogle(result.data.idToken);
break;
case CredentialsType.PASSWORD:
await api.signIn(result.data.username, result.data.password);
break;
case CredentialsType.CANCELLED:
showSignInScreen();
break;
}

AppleIdCredentialState​

Resolved by getAppleIdCredentialState (iOS).

ValueMeaningWhat to do
AUTHORIZEDThe user is still signed in to the app with Apple IDNothing
REVOKEDThe user stopped using Apple ID with the appSign them out
NOT_FOUNDNo credential for this user idSign them out
TRANSFERREDThe app was transferred to another teamMigrate the user id

CredentialError​

The code of every rejection. Each code, its causes and how to handle it are in Errors.

ValueMeaning
CONFIGURATION_ERRORThe app is misconfigured (missing Google client id or URL scheme, invalid redirectUri)
NOT_SUPPORTED_ERRORThe OS version, missing Play Services or the platform does not support the method
NO_SIGN_IN_AVAILABLEThere is no credential to return (no account, passkey or previous sign in)
BROWSER_UNAVAILABLEThe browser session could not be opened
NO_ACTIVITY_ERRORNo Android activity or iOS view controller to present the UI
SIMULTANEOUS_CALL_ERRORiOS: the same method is still waiting for the previous call
NETWORK_ERRORoauthSignIn: the token endpoint request failed
INVALID_RESULT_ERRORThe provider failed or returned something unexpected
NO_PLAY_SERVICES_ERRORDeprecated, never used. Missing Play Services rejects with NOT_SUPPORTED_ERROR

Error types​

CredentialErrorCode​

String union of the CredentialError values. Accepts both the enum members and their strings.

type CredentialErrorCode = `${CredentialError}`;
// 'CONFIGURATION_ERROR' | 'NOT_SUPPORTED_ERROR' | 'NO_SIGN_IN_AVAILABLE' | ...

OauthEssentialsError​

What the promises of the library reject with: an Error with a code. The native error text is in message.

type OauthEssentialsError<C extends CredentialErrorCode = CredentialErrorCode> = Error & { code: C };

isCredentialError(error, code?)​

Type guard for catch blocks. Returns true when error is an object whose code is a CredentialError value, and equals code when given. It never throws.

function isCredentialError<C extends CredentialErrorCode = CredentialErrorCode>(
error: unknown,
code?: C
): error is OauthEssentialsError<C>;
import { googleSignIn, isCredentialError, CredentialError } from 'react-native-oauth-essentials';

try {
await googleSignIn();
} catch (e) {
if (isCredentialError(e, CredentialError.CONFIGURATION_ERROR)) console.error(e.message);
else if (isCredentialError(e)) report(e.code, e.message);
else throw e;
}