刷新Microsoft Live API的OAuth访问令牌

reb*_*o95 5 rest oauth access-token microsoft-live-connect

目前,我让用户通过在Web视图中向以下URL发送请求来登录Microsoft Live:

https://login.live.com/oauth20_authorize.srf?client_id=[CLIENT ID]&scope=[SCOPES]&response_type=token&redirect_uri=[REDIRECT URI]&display=popup
Run Code Online (Sandbox Code Playgroud)

这完美地工作,我收到并保存access_tokenauthentication_token.请注意refresh_token,即使我包含wl.offline_access范围,它也不会返回a .

访问令牌过期并需要刷新时会出现此问题.我正在尝试使用Microsoft文档中的方法刷新令牌:

https://login.live.com/oauth20_token.srf?client_id=[CLIENT ID]&redirect_uri=[REDIRECT URI]&client_secret=[CLIENT SECRET]&refresh_token=[WHAT TO PUT HERE?]&grant_type=refresh_token
Run Code Online (Sandbox Code Playgroud)

但是,a refresh_token在登录时从未返回,所以我不确定要传入什么.请注意,发送authentication_token(它应该用于什么?)作为refresh_token参数会导致以下结果:

{
  "error": "invalid_grant",
  "error_description": "The provided value for the input parameter 'refresh_token' is not valid."
}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何通过REST API正确刷新Microsoft Live令牌?

reb*_*o95 8

在进一步阅读微软的文档和实验后,我能够弄清楚如何做到这一点.

我最初尝试的问题是我wl.offline_access在使用隐式授权流时请求范围,因为他们的文档说不:

注意wl.offline_access如果您使用隐式授权流(response_type=token),请不要包括范围.

所以,我将我的URL更改为以下内容(使用授权代码授权流程,因为我需要离线访问):

https://login.live.com/oauth20_authorize.srf?client_id=[CLIENT ID]&scope=[SCOPES]&response_type=code&redirect_uri=[REDIRECT URI]&display=popup
Run Code Online (Sandbox Code Playgroud)

然后,一旦我收到code回调函数,我就调用了以下端点来检索访问权限并刷新令牌:

https://login.live.com/oauth20_token.srf?client_id=[CLIENT ID]&redirect_uri=[REDIRECT URI]&client_secret=[CLIENT SECRET]&code=[CODE FROM AUTHORIZATION]&grant_type=authorization_code
Run Code Online (Sandbox Code Playgroud)

注意:在上述链接中,Microsoft的文档对于此端点是INCORRECT.这是一个GET请求,而不是POST他们的文档声明的请求.

这个方法最终返回了access_tokenrefresh_token参数,我能够按预期使用它们.