question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android authentication failed idToken not vaild

See original GitHub issue

Issue

I’m trying to implement google login with oauth2, it worked the first time, then the day after i open the project and every time i try to refresh the token or get a new one i get this error “Invalid ID Token”

On ios it works as expected

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 = "iosClientId"
const ANDROID_CLIENT_ID = "androidClientId"

const IOS_REDIRECT_URI = "iosRedirectUri"
const ANDROID_REDIRECT_URI = "androidRedirectUri"

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);
  }
}

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

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


Environment

  • Your Identity Provider: Google
  • Platform that you’re experiencing the issue on: Android
  • Are you using Expo? No

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
fbeccacecicommented, Dec 28, 2021

I found out that the emulator i was using (Android 12 pixel 5) didn’t manage to update the system date correctly so the emulator time was a random day in the past and this causes the authentication to fail, i created a new emulator with android 11 and set the date to the correct day and since then everything worked well

0reactions
panktiszluckcommented, Apr 27, 2022

Hey @fbeccaceci did you manage to solve the issue? As I am getting the same error here?

Same, here getting same issue in ios

Read more comments on GitHub >

github_iconTop Results From Across the Web

I'm getting the "Your token is invalid [401]" error
This error means that the app has experienced an authentication problem and can't verify your account information. If it occurs, you'll be automatically...
Read more >
Troubleshoot Invalid Token Errors - Auth0
Error Message: The ID token cannot be validated because it was signed using the HS256 algorithm and public applications (such as a browser)...
Read more >
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. ... I can't understand the problem ...
Read more >
Verify the Google ID token on your server side | Authentication
The ID token is properly signed by Google. · The value of aud in the ID token is equal to one of your...
Read more >
What does 'invalid login token detected' mean?
This can sometimes happen when an update is released for the app. Since you were last logged in to a different version of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found