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).
}
我:
- 需要申请
offline_access
还是仅适用于 access tokens
? (在我的测试中,它似乎只刷新访问令牌)。
Research/Things 我试过了:
- https://auth0.com/learn/refresh-tokens/ seems to indicate I just set
openid
scope, but I'm doing that and only getting the intial id_token. Do I need to refresh the token with prompt=none
parameters and make another login call? 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_token
和access token
。不幸的是,access token
到期时间锁定在 24 小时,除非你做额外的工作。
确保在创建 Auth0Account 实例时有 setOIDCCompliant
到 true
,否则更新调用将到达 /delegation
端点,该端点现已弃用,仅在以下情况下有效您的客户端 ID 已设置为支持非 oidc 兼容调用。
需要注意的另一件事有点跑题了。如果出现任何问题,SecureCredentialsManager
会清除凭据。这对我来说是不可接受的,因为只是离线并且无法拨打电话会导致凭据被清除。
我已经连接了 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).
}
我:
- 需要申请
offline_access
还是仅适用于access tokens
? (在我的测试中,它似乎只刷新访问令牌)。
Research/Things 我试过了:
- https://auth0.com/learn/refresh-tokens/ seems to indicate I just set
openid
scope, but I'm doing that and only getting the intial id_token. Do I need to refresh the token withprompt=none
parameters and make another login call? 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_token
和access token
。不幸的是,access token
到期时间锁定在 24 小时,除非你做额外的工作。
确保在创建 Auth0Account 实例时有 setOIDCCompliant
到 true
,否则更新调用将到达 /delegation
端点,该端点现已弃用,仅在以下情况下有效您的客户端 ID 已设置为支持非 oidc 兼容调用。
需要注意的另一件事有点跑题了。如果出现任何问题,SecureCredentialsManager
会清除凭据。这对我来说是不可接受的,因为只是离线并且无法拨打电话会导致凭据被清除。