Android authentication failed idToken not vaild
See original GitHub issueIssue
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:
- Created 2 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Same, here getting same issue in ios