【发布时间】:2018-03-12 06:14:46
【问题描述】:
我正在尝试使用 Microsoft Single Sign on 登录我的 android 应用程序,并使用 here 提供的 MSAL 实现。
在 onCreate 中
mApp = new PublicClientApplication(this.getApplicationContext(), API.CLIENT_ID, API.AUTHORITY);
当用户按下“Sign in with Microsoft”选项时,我调用获取token的方法
mApp.acquireToken(this, getResources().getStringArray(R.array.msal_scopes), getAuthInteractiveCallback());
在 onActivityResult 处理重定向请求后,我在回调中获取身份验证响应为
private AuthenticationCallback getAuthInteractiveCallback() {
return new AuthenticationCallback() {
@Override
public void onSuccess(AuthenticationResult authenticationResult) {
/* Successfully got a token, use it to call a protected resource */
accessToken = authenticationResult.getAccessToken();
Log.d("AuthSuccess"," "+accessToken);
}
@Override
public void onError(MsalException exception) {
/* Failed to acquireToken */
Log.d("AuthFail"," "+exception.getMessage());
if (exception instanceof MsalClientException) {
/* Exception inside MSAL, more info inside MsalError.java */
} else if (exception instanceof MsalServiceException) {
/* Exception when communicating with the STS, likely config issue */
}
}
@Override
public void onCancel() {
/* User canceled the authentication */
}
};
}
问题是,AuthenticationResult 对象给出了access token,而不是refresh token。该对象根本没有刷新令牌作为其参数之一。我是否还需要进一步调用另一种方法来获取刷新令牌?如何使用 MSAL 从 Microsoft 单点登录获得访问令牌和刷新令牌?!
【问题讨论】: