适用于Android的AzureAD抛出ADALError.AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED
作者:互联网
我有一个应用程序,其中用户在Office365中使用AzureAD library for Android进行身份验证.
它运行良好,用户可以进行身份验证并使用该应用程序.不幸的是,过了一会儿,他们开始将身份验证异常与ADALError.AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED一起作为错误代码.
我检查了AzurelAD的source code.解决此问题的唯一地方是acquireTokenAfterValidation()方法:
private AuthenticationResult acquireTokenAfterValidation(CallbackHandler callbackHandle,
final IWindowComponent activity, final boolean useDialog,
final AuthenticationRequest request) {
Logger.v(TAG, "Token request started");
// BROKER flow intercepts here
// cache and refresh call happens through the authenticator service
if (mBrokerProxy.canSwitchToBroker()
&& mBrokerProxy.verifyUser(request.getLoginHint(),
request.getUserId())) {
.......
Logger.v(TAG, "Token is not returned from backgroud call");
if (!request.isSilent() && callbackHandle.callback != null && activity != null) {
....
} else {
// User does not want to launch activity
String msg = "Prompt is not allowed and failed to get token:";
Logger.e(TAG, msg, "", ADALError.AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED);
callbackHandle.onError(new AuthenticationException(
ADALError.AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED, msg));
}
// It will start activity if callback is provided. Return null here.
return null;
} else {
return localFlow(callbackHandle, activity, useDialog, request);
}
}
我的源代码:
authenticator.getAccessTokenSilentSync(getMailService());
public class Authenticator {
..............
public String getAccessTokenSilentSync(ServiceInfo serviceInfo) {
throwIfNotInitialized();
return getAuthenticationResultSilentSync(serviceInfo).getAccessToken();
}
private AuthenticationResult getAuthenticationResultSilentSync(ServiceInfo serviceInfo) {
try {
return authenticationContext.acquireTokenSilentSync(
serviceInfo.ServiceResourceId,
Client.ID,
userIdentity.getAdUserId());
} catch (AuthenticationException ex) {
// HERE THE EXCEPTION IS HANDLED.
}
}
..............
}
我得到的Stacktrace:
06002
我正在使用的AzureAD库的版本:1.1.7(为防止责备太旧的版本-从1.1.7到1.1.11,我检查了变更列表,但未发现与问题相关的任何内容)
问题:现在,我正在处理此错误,作为通过用户进入登录屏幕的信号.我认为,这会给用户带来糟糕的体验.它经常发生并影响许多用户的事实使它变得更糟.
问题:我可以采取其他措施来避免AuthenticationException或以某种方式解决此问题(即避免用户再次输入凭据).
解决方法:
您是否已验证AuthenticationContext.acquireTokenSilentSync()确实是您要调用的方法?
文档指示此方法将明确不显示提示.从文档:
This is sync function. It will first look at the cache and automatically checks for the token expiration. Additionally, if no suitable access token is found in the cache, but refresh token is available, the function will use the refresh token automatically. This method will not show UI for the user. If prompt is needed, the method will return an exception.
发出的刷新令牌应每AAD book持续两周.刷新令牌过期后,用户应重新进行身份验证.您可以检查Fiddler或Charles的净流量并检查令牌的到期时间吗?如果可以在令牌到期之前验证令牌刷新失败,则可能表明AD库中存在错误.
为了阐明AuthenticationContext上方法的区别-有两类方法:“静默”方法(如果需要重新验证,将不会向用户显示对话框)和非静默方法.如果要求用户重新认证(或同意),则非静默方法将启动一个包含AAD登录名的新活动.此时,身份验证流程将重新启动.
此外,如果您更改了应用程序在Azure中的注册,例如添加了新的权限范围,则将要求您的用户重新授予同意,以便应用程序继续处理其数据.
标签:adal,azure-active-directory,office365,android 来源: https://codeday.me/bug/20191119/2034431.html