【问题标题】:Can only get either a long access token or a refresh token只能获取长访问令牌或刷新令牌
【发布时间】:2018-03-02 05:40:00
【问题描述】:

我正在使用 react-native-auth0 sdk。这是我使用 auth0 进行 facebook 登录的方法。

auth0
    .webAuth
    .authorize({
        scope: 'openid profile email offline_access', 
        //audience: config.auth0.audience,      //option (1)
        audience: auth0Domain+'/userinfo',      //option (2)
        responseType: 'token id_token',
    })
    .then(auth0Cred => {
        console.log("Auth0 Auth Result: "+JSON.stringify(auth0Cred));
        dispatch(signInAuth0Successful(auth0Cred));
        if (callback != null) {
            callback(auth0Cred);
        }

        dispatch(saveAuth0RefreshToken(auth0Cred.refreshToken));

        //return auth0Cred;
    })
    .catch(error => console.log(error));

对于观众,我有两种选择。

当我使用选项 (1) 时,它给了我 accessToken、idToken、scope、expiresIn、tokenType 的(长版本)。

当我使用选项 (2) 时,它给了我 accessToken、idToken、refreshToken、expiresIn、tokenType 的(不透明版本)。

但是,我同时需要长 accessToken 和 refreshToken 吗?有可能吗?

【问题讨论】:

    标签: react-native auth0


    【解决方案1】:

    说明 - 当您为自己的 API 使用 audience 时,您选择接收 JWT 访问令牌(长令牌)。如果您只需要调用 Auth0 /userInfo 端点,那么默认行为只是提供不透明的访问令牌 - 这是预期的行为(如果有些混乱)。

    出于兴趣,如果您不指定自己的受众,为什么还需要 JWT 访问令牌?

    但是,要尝试解决您的请求 - 请检查您是否已将 Auth0 仪表板中的客户端设置为 OIDC Conformant。在Clients -> Your Client -> Settings - Advanced 下(在页面底部)。截图如下:

    如果这不起作用,我们可以探索其他选项 - 如果需要,请在下方留言。

    使用 OIDC 一致性,您将不会收到 SPA(隐式流)的刷新令牌。相反,请使用静默身份验证 - 请参阅 reference docs here,因此请确保您将客户端类型设置为 Native

    基于 OP 反馈 - 检查资源服务器是否也启用了 allow_offline_access。可以使用 Management API 对此进行修补。或者,只需转到 Auth0 仪表板中的 API,然后在 API 设置页面上切换开关。

    【讨论】:

    • 我将拥有一个提供 RESTful API 的后端服务器。在这种情况下,我应该为我的观众使用选项(1)吗?目前,我使用 localhost 作为我的后端
    • 我已经设置了OIDC Conformant,但还是无法获取refreshToken
    • 在客户端刷新访问令牌的建议方法是什么?
    • 再次查看更新。 @ykn121 - 如果你想在聊天室私信告诉我。
    • 非常感谢。我终于通过在 Management API 中启用 Allow Offline Access 来获得刷新令牌。
    猜你喜欢
    • 2015-07-19
    • 2017-03-22
    • 1970-01-01
    • 2020-03-10
    • 2022-01-23
    • 2015-01-08
    • 2020-02-26
    • 2019-09-09
    • 2013-08-23
    相关资源
    最近更新 更多