【问题标题】:Getting an id_token using Auth0 in Expo app在 Expo 应用程序中使用 Auth0 获取 id_token
【发布时间】:2018-12-11 17:33:07
【问题描述】:

我在一个新的 Expo/React Native 应用程序中实现 Auth0 身份验证,遵循以下示例: https://github.com/expo/auth0-example

我唯一更改的是scope: 'openid profile',在示例中为scope: 'openid name',尽管我也使用示例中的代码进行了尝试。

正如您在以下屏幕截图中所见,我得到的是 access_token 而不是 id_token

这是使用 Auth0 进行身份验证的代码:

_loginWithAuth0 = async () => {
    const redirectUrl = AuthSession.getRedirectUrl();
    console.log(`Redirect URL (add this to Auth0): ${redirectUrl}`);
    const result = await AuthSession.startAsync({
      authUrl: `${auth0Domain}/authorize` + toQueryString({
        client_id: auth0ClientId,
        response_type: 'token',
        scope: 'openid profile',
        redirect_uri: redirectUrl,
      }),
    });
    console.log(result);
    if (result.type === 'success') {
      this.handleParams(result.params);
    }
  }

我尝试将response_type 更改为token id_token,但抛出了配置错误提示。

如何获得id_token

【问题讨论】:

  • 能否请您提供配置错误。

标签: react-native expo auth0


【解决方案1】:

返回的令牌由response_type 定义,而不是scope。对于 ID 令牌,范围确定令牌中返回的内容。你需要response_type: 'id_token'

您可以在此处阅读有关其工作原理的更多信息:https://auth0.com/docs/tokens/id-token#control-the-contents-of-an-id-token

完全披露,我为 Auth0 工作。

【讨论】:

    猜你喜欢
    • 2017-06-02
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 2017-04-04
    • 2020-06-27
    • 2018-08-04
    • 1970-01-01
    • 2021-10-22
    相关资源
    最近更新 更多