【问题标题】:React-Native Expo AuthSession oAuth2 Google LogoutReact-Native Expo AuthSession oAuth2 Google Logout
【发布时间】:2022-04-12 22:27:56
【问题描述】:

我正在尝试使用 expo authsession 退出 google,但它总是返回错误消息:无法撤销令牌:RevokeTokenRequest 需要有效的令牌才能撤销。我已经尝试放置 Bearer ${google_access_token} 和 ${google_access_token} 但没有成功。

  //LOGOUT GOOGLE
  const handleLogoutGoogle = async () => {
    let config = {
      issuer: "https://accounts.google.com/o/oauth2/v2/logout",
      scopes: ["openid", "profile"],
      /* This is the CLIENT_ID generated from a Firebase project */
      clientId: "cccccccccc-aio1fviva82o78umts2k4uvsn1val515.apps.googleusercontent.com",
    };
    const google_access_token = await AsyncStorage.getItem("@myApp:googleAccessToken");
    if (google_access_token) {
      console.log(`Bearer ${google_access_token}`);
      try {
        await AuthSession.revokeAsync(config, {
          token: `${google_access_token}`,
          isClientIdProvided: true,
        });
        await AsyncStorage.removeItem("@myApp:googleAccessToken");
        return null;
      } catch (e) {
        console.log(`Failed to revoke token: ${e.message}`);
      }
    }
  };
  //LOGOUT GOOGLE

【问题讨论】:

  • 嘿,艾迪!你有没有熬过这个?
  • 嗨,伙计!不,我不能
  • 您是否尝试过将 Firebase 与身份验证会话集成?
  • 事实上,我什至无法使用 Expo 实现 Google 登录以正常工作
  • 所以没有身份验证流程与 expo-auth-session 一起使用?

标签: react-native oauth-2.0 expo


【解决方案1】:

我可以如下注销:登录时,我将令牌存储在localStorage中,在注销方法中,我做了如下:

//LOGOUT GOOGLE
    const token = await AsyncStorage.getItem("@ellot:googleAccessToken");
    if (token) {
      try {
        await AuthSession.revokeAsync({ token }, { revocationEndpoint: 'https://oauth2.googleapis.com/revoke' });
        await AsyncStorage.removeItem("@my:googleAccessToken");
      } catch (error) {
        console.log('ERROR XXX', error)
      }
    }
    //LOGOUT GOOGLE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多