4

我正在使用以下代码以及我的刷新令牌来请求新的访问令牌:

exports.getTokenFromRefreshToken = function (user, callback) {
    request.post({
        url:'https://login.microsoftonline.com/12345678-1234-1234-1234-2f189712345/oauth2/token',
        form: {
            grant_type: 'refresh_token',
            refresh_token: refresh_token,
            client_id: client_id,
            client_secret: client_secret,
            resource: 'https://graph.microsoft.com'
        }
    }, function(err, httpResponse, body) {
        if (!err) {
            var tokens = JSON.parse(httpResponse.body);
            console.log('getTokenFromRefreshToken() tokens = ' + JSON.stringify(tokens));
            callback(null, tokens);
        }
    })
};

httpResponse包括我发出原始令牌请求(来自 )时获得的所有内容code,但没有新的刷新令牌。我的印象是我也会收到一个新的刷新令牌。不是这样吗?

4

4 回答 4

4

仅当您包含offline_access范围时,您才会获得新的刷新令牌。

参考:https ://azure.microsoft.com/en-us/documentation/articles/active-directory-v2-scopes/

offline_access 范围使您的应用程序可以在较长时间内代表用户访问资源。在工作帐户同意页面上,此范围显示为“随时访问您的数据”权限。在个人 Microsoft 帐户同意页面上,它显示为“随时访问您的信息”权限。当用户批准 offline_access 范围时,您的应用程序可以从 v2.0 令牌端点接收刷新令牌。刷新令牌是长期存在的。当旧的访问令牌过期时,您的应用可以获得新的访问令牌。

于 2016-11-04T21:10:46.240 回答
0

我有完全相同的问题,引起了一段时间的头痛,直到发现问题为止。

似乎您可能正在使用访客 MS 帐户(以前称为 Live)登录,因此获得了 12 小时到期刷新令牌,没有滚动窗口。

您需要使用完整的 MS 帐户在响应正文中获取刷新令牌(这是一个将持续 14 天的令牌),滚动窗口为 90 天。

只要您使用访客 MSA,您就不会获得刷新令牌。据我所见,您的代码结构正确,而且我认为您不需要如上所述的 redirect_uri 标头,根据 doco,它们是可选字段。

有关刷新令牌类型的更多信息,请参阅此博客文章:

Azure 令牌

于 2016-02-24T03:17:36.863 回答
0

It looks like it should work except you seem to be missing the redirect URI. I have a working version of this call but it includes this redirect_uri. It produces for me both a new access and refresh token.

--

http://graph.microsoft.io/en-us/docs/authorization/app_authorization

Renew expiring access token using refresh token

The redirect URL that the browser is sent to when authentication is complete. This should match the redirect_uri value used in the first request.

于 2016-02-18T11:28:03.303 回答
0

刷新令牌的刷新方式与使用刷新令牌获取新访问令牌的方式不同。当刷新令牌过期时,您需要获取凭证并再次进行初始令牌获取。

此处的更多信息:刷新访问令牌

于 2016-02-10T22:10:55.470 回答