【问题标题】:Auth0 Android - How to renew id_token?Auth0 Android - 如何更新 id_token?
【发布时间】:2019-12-08 10:23:08
【问题描述】:

我已经连接了 Auth0 和 cognito。我可以登录应用程序,一切正常。在id_token 过期之前,一切都会失败。

刷新/续订id_tokens 的符合 ODIC 标准的方法是什么?

以下代码仅为我刷新访问令牌。

初始授权:

 WebAuthProvider.login(auth0CredentialsManager.getAuth0Account())
                .withScope("openid email profile offline_access") // is offline_access required?
                .withResponseType(ResponseType.ID_TOKEN | ResponseType.CODE | ResponseType.TOKEN) // I'm not sure if this is necessary to specify...
                .withParameters(params)
                .withAudience(String.format("https://%s/userinfo", BuildConfig.AUTH0_DOMAIN))
                .start(Auth0LoginActivity.this, new AuthCallback() {
                    @Override
                    public void onFailure(@NonNull Dialog dialog) {
                        // Show error Dialog to user
                        dialog.show();
                        onAuth0Failure(null);
                    }

                    @Override
                    public void onFailure(AuthenticationException exception) {
                        Bugsnag.notify(exception);
                        onAuth0Failure(exception);
                        // Show error to user
                    }

                    @Override
                    public void onSuccess(@NonNull Credentials credentials) {
                        handleSignIn(credentials); //this call saves credentials using SecureCredentialsManager.  If you want to see it let me know
                    }
                });

当我需要获得一个新的id_token 时,我正在尝试这个(但它只会刷新访问令牌):

        // auth0CredentialsManager is SecureCredentialsManager
        auth0CredentialsManager.getCredentials(new BaseCallback<Credentials, CredentialsManagerException>() {
            @Override
            public void onSuccess(Credentials credentials) {
                auth0CredentialsManager.saveCredentials(credentials);
                //  do more stuff here... except the id_token is expired (access token is not).
            }

我:

  • 需要请求offline_access 还是只针对access tokens? (在我的测试中,它似乎只刷新访问令牌)。

研究/我尝试过的事情:

  • https://auth0.com/learn/refresh-tokens/ 似乎表明我刚刚设置了openid 范围,但我正在这样做并且只获得初始id_token。我是否需要使用prompt=none 参数刷新令牌并再次进行登录调用? https://auth0.com/docs/api-auth/tutorials/silent-authentication 似乎表明只有单页应用程序才需要静默登录。
  • AuthenticationAPIClient.delegationWithRefreshToken 看起来是正确的调用,但它总是抛出 com.auth0.android.authentication.AuthenticationException: An error occurred when trying to authenticate with the server.

【问题讨论】:

    标签: android oauth-2.0 openid amazon-cognito auth0


    【解决方案1】:

    好的,这就是我学到的。

    从 1.18.0 版开始,对 getCredentials 的调用考虑 id 令牌过期。它检查访问令牌是否过期,如果过期,它将刷新id_tokenaccess token。不幸的是,access token 的到期时间被锁定为 24 小时,除非您做额外的工作。

    确保您在创建 Auth0Account 实例时拥有 setOIDCComplianttrue,否则对更新的调用将命中 /delegation 端点,该端点现已弃用,仅当您的客户端 ID 设置为支持非oidc 兼容调用。

    另一件需要注意的事情有点离题了。如果出现任何问题,SecureCredentialsManager 会清除凭据。这对我来说是不可接受的,因为只是离线并且无法拨打电话会导致凭据被清除。

    【讨论】:

      猜你喜欢
      • 2017-02-03
      • 1970-01-01
      • 2017-06-02
      • 2017-07-25
      • 1970-01-01
      • 2018-05-17
      • 2017-04-04
      • 1970-01-01
      • 2021-08-08
      相关资源
      最近更新 更多