Auth0 Android - 如何续订 id_token?

Auth0 Android - How to renew id_token?

我已经连接了 Auth0 和 cognito。我可以登录该应用程序,一切正常。直到 id_token 过期,然后一切都失败了。

refresh/renew 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).
            }

我:

Research/Things 我试过了:

好的,这就是我学到的东西。

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

确保在创建 Auth0Account 实例时有 setOIDCComplianttrue,否则更新调用将到达 /delegation 端点,该端点现已弃用,仅在以下情况下有效您的客户端 ID 已设置为支持非 oidc 兼容调用。

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