【问题标题】:Refreshing an OAuth access token for Microsoft Live API刷新 Microsoft Live API 的 OAuth 访问令牌
【发布时间】:2015-04-04 20:00:05
【问题描述】:

目前,我让用户通过在 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

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

访问令牌过期需要刷新时会出现问题。我正在尝试使用Microsoft's documentation 中的方法刷新令牌:

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

但是,refresh_token 从未在登录中返回,所以我不确定要传递什么。请注意,将authentication_token(它应该用于什么?)作为refresh_token 发送参数结果如下:

{
  "error": "invalid_grant",
  "error_description": "The provided value for the input parameter 'refresh_token' is not valid."
}

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

【问题讨论】:

  • 你弄清楚如何获取刷新令牌了吗?

标签: rest oauth access-token microsoft-live-connect


【解决方案1】:

在进一步阅读微软的documentation 并进行实验后,我能够弄清楚如何做到这一点。

我最初尝试的问题是我在使用 implicit grant flow 时请求了 wl.offline_access 范围,因为他们的文档说不这样做:

注意,如果您使用的是 隐式授权流 (response_type=token)。

因此,我将 URL 更改为以下内容(使用 authorization code grant flow,因为我需要离线访问):

https://login.live.com/oauth20_authorize.srf?client_id=[CLIENT ID]&scope=[SCOPES]&response_type=code&redirect_uri=[REDIRECT URI]&display=popup

然后,一旦我在回调中收到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

注意:对于上述链接中的此端点,Microsoft 的文档不正确。这是一个GET 请求,而不是他们文档声称的POST 请求。

这个方法终于返回了access_tokenrefresh_token参数,我可以按预期使用这两个参数。

【讨论】:

  • 那么你用来从一个驱动器调用数据的 url 是什么。我将api.onedrive.com/v1.0/drive 与授权一起使用:不记名{token}。但它返回“身份验证失败”
  • 这对我不起作用。如果我收到请求,我会收到此错误:“error_description”:“提供的请求必须具有内容类型'application/x-www-form-urlencoded'。”
  • 听起来你应该将application/x-www-form-urlencoded 设置为Content-Type 标题然后@user2924482 :)
猜你喜欢
  • 1970-01-01
  • 2015-04-01
  • 2014-07-15
  • 2022-01-12
  • 2017-06-09
  • 2021-09-13
  • 1970-01-01
  • 2015-08-21
  • 1970-01-01
相关资源
最近更新 更多