代码之家  ›  专栏  ›  技术社区  ›  Sam

在Expo应用程序中使用Auth0获取ID_令牌

  •  1
  • Sam  · 技术社区  · 6 年前

    i_m在新的expo/react本机应用程序中实现Auth0身份验证,如下示例: https://github.com/expo/auth0-example

    我唯一改变的是 scope: 'openid profile' 在这个例子中 scope: 'openid name' 尽管我也用示例中的代码进行了尝试。

    正如您在下面的屏幕截图中看到的,我得到一个 access_token 而不是 id_token : enter image description here

    以下是要用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 但是抛出一个错误,说配置错误。

    我如何得到一个 IDK令牌 ?

    1 回复  |  直到 6 年前
        1
  •  0
  •   lukeocodes    6 年前

    返回的令牌由 response_type 而不是 scope .在ID令牌的情况下,作用域确定令牌中返回的内容。你需要 response_type: 'id_token' .

    您可以在这里阅读更多关于它如何工作的信息: https://auth0.com/docs/tokens/id-token#control-the-contents-of-an-id-token

    完全公开,我为Auth0工作。