Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep getting error Invalid ID Token with react-native-app-auth

I'm currently trying to authenticate users with google oauth in a react-native app with react-native-app-auth.

This is my code

import * as AppAuth from 'react-native-app-auth';

import { AuthorizationError } from '../errors';
import { GooglePeopleApis } from '@apis';
import { Platform } from 'react-native';

const IOS_CLIENT_ID = "placeholder_client_id"
const ANDROID_CLIENT_ID = "placeholder_client_id"

const IOS_REDIRECT_URI = "placeholder_ios_redirect_url"
const ANDROID_REDIRECT_URI = "placeholder_android_redirect_url"

const config = {
  issuer: 'https://accounts.google.com',
  clientId: Platform.select({ios: IOS_CLIENT_ID, android: ANDROID_CLIENT_ID})!,
  redirectUrl: Platform.select({ios: IOS_REDIRECT_URI, android: ANDROID_REDIRECT_URI})!,
  scopes: ['https://mail.google.com/', "profile", "email"]
};

export interface AuthorizationResponse {
  accessToken: string;
  accessTokenExpirationDate: string;
  refreshToken: string;
  emailAddress: string;
}

export const authorize = async (): Promise<AuthorizationResponse> => {
  try {
    let result = await AppAuth.authorize(config);
    const emailAddress = await GooglePeopleApis.fetchMyEmailAddress(result.accessToken)

    return {
      accessToken: result.accessToken,
      accessTokenExpirationDate: result.accessTokenExpirationDate,
      refreshToken: result.refreshToken,
      emailAddress
    }
  } catch(err) {
    const error = err as Error
    throw new AuthorizationError(error.message);
  }
}

On ios it works fine, on android it worked the first time but then when i came back to the project the day after it started giving me an error like the following

ReactNativeJS: [Error: Invalid ID Token]

I can't understand the problem since i'm not passing any id token in the auth request. The browser opens as expected, i select my google account but then it returns this error.

react-native: 0.66.3 react-native-app-auth: 6.4.0

like image 397
Fabrizio Beccaceci Avatar asked May 08 '26 06:05

Fabrizio Beccaceci


1 Answers

Check if the emulator date and time are correct.

like image 94
Fakfa Chuchit Avatar answered May 10 '26 02:05

Fakfa Chuchit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!