我目前正在一个react-native-app-auth的react-native应用中尝试使用google oauth对用户进行身份验证。
这是我的密码
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);
}
}
在iOS上它工作得很好,在Android上它第一次工作,但当我回到项目的第二天,它开始给我一个错误,如下所示
React型原生JS:[错误:无效的ID令牌]
我不明白这个问题,因为我没有在auth请求中传递任何id令牌。浏览器按预期打开,我选择了我的google帐户,但它返回了这个错误。
原生React:0.66.3React Native应用程序身份验证:6.4.0
2条答案
按热度按时间y1aodyip1#
我得到了同样的错误。我继续删除了模拟设备,并创建了一个新的,然后它工作了。希望这对你有帮助。
How to delete emulated device
acruukt92#
检查仿真器的日期和时间是否正确。