Auth0 Android-如何续订ID_Token



我有auth0和cognito均已连接。我可以登录到该应用程序,一切都很好。在id_token到期之前,一切都失败了。

刷新/续订id_tokens的ODIC一致方法是什么?

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

初始auth:

 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范围,但是我正在这样做,并且只能获得Intial 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.

好吧,这就是我学到的。

从1.18.0版本开始, getCredentials的呼叫请考虑ID令牌到期。它仅检查访问令牌是否过期,如果是,则将刷新id_tokenaccess token。不幸的是,除非您进行其他工作,否则access token到期在24小时内被锁定。

创建auth0account实例时,请确保您有setOIDCComplianttrue,否则续订呼叫将击中/delegation端点,该端点现在已弃用,并且仅在设置您的客户端ID来支持非OIDC兼容的呼叫时才有效。p>另一件事要意识到这有点不合时宜。SecureCredentialsManager如果出现任何问题,可以清除凭据。这对我来说是不可接受的,因为仅仅是离线而无法进行呼叫会导致凭证被清除。

相关内容

最新更新