如何在android中使用Microsoft身份验证库(Msal)获取刷新令牌

时间:2018-03-12 06:14:47

标签: android single-sign-on

我正在尝试使用Microsoft Single Sign on登录我的Android应用程序,使用here提供的MSAL实现。

在onCreate

mApp = new PublicClientApplication(this.getApplicationContext(), API.CLIENT_ID, API.AUTHORITY);

当用户按下"使用Microsoft"选项,我将该方法称为

获取令牌
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单点登录获取访问和刷新令牌?!

1 个答案:

答案 0 :(得分:0)