【问题标题】:Another user onedrive files using access token另一个使用访问令牌的用户 onedrive 文件
【发布时间】:2017-06-11 19:42:55
【问题描述】:
我是用户X。我需要从 api 访问 userY onedrive 文件并上传文件。 当我向 https://login.microsoftonline.com/tenant/oauth2/token 发送用户令牌请求时,我得到了它。 POST 令牌请求: 网址:https://login.microsoftonline.com/tenant/oauth2/token 授予类型:密码 用户名:userY 密码:***(我的密码)*** 资源:***(我的资源)*** client_id:***(我的客户 ID)*** client_secret:***(我的客户密码)*** 回复: "token_type": "承载者", "范围": "AllSites.FullControl AllSites.Manage AllSites.Read AllSites.Write Calendars.Read Calendars.Read.Shared Calendars.ReadWrite Calendars.ReadWrite.Shared Contacts.Read Contacts.Read.Shared Contacts.ReadWrite Contacts.ReadWrite.Shared Directory .AccessAsUser.All Directory.Read.All Directory.ReadWrite.All email Files.Read Files.Read.All Files.Read.Selected Files.ReadWrite Files.ReadWrite.All Files.ReadWrite.AppFolder Files.ReadWrite.Selected Group.Read.所有 Group.ReadWrite.All IdentityRiskEvent.Read.All Mail.Read Mail.Read.Shared Mail.ReadWrite Mail.ReadWrite.Shared Mail.Send Mail.Send.Shared MailboxSettings.ReadWrite Member.Read.Hidden MyFiles.Read MyFiles.Write Notes .Create Notes.Read Notes.Read.All Notes.ReadWrite Notes.ReadWrite.All Notes.ReadWrite.CreatedByApp offline_access openid People.Read profile Reports.Read.All Sites.Read.All Sites.ReadWrite.All Sites.Search.All Tasks .Read Tasks.Read.Shared Tasks.ReadWrite Tasks.ReadWrite.Shared TermStore.Read.All TermStore.ReadWrite.All User.Read User.Read.All User.ReadBasic.All User.ReadWrite User.ReadWrite.All", "expires_in": "3599", “ext_expires_in”:“0”, "expires_on": "1485157695", "not_before": "1485153795", “资源”:***(我的资源)*** "access_token": "***这是我的访问令牌***" "refresh_token": "***这是我的刷新令牌***" 我尝试使用这个令牌: 第一个例子(不合适:Kevin 解释如下): 获取请求 网址:https://api.office.com/discovery/v2.0/me/services 标头授权:Bearer ***这是我的访问令牌*** 回复: { “错误”: { "code": "-2147024891, System.UnauthorizedAccessException", "message": "拒绝访问。您无权执行此操作或访问此资源。" } } 第二个例子: 获取请求 网址:http://tenant.sharepoint.com/_api/search/query?querytext='*' 标头授权:Bearer ***这是我的访问令牌*** 回复: {"error_description":"引发了 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' 类型的异常。"} 第三个例子: 发布请求: 网址:https://tenant-my.sharepoint.com/_api/v2.0 标头授权:Bearer ***这是我的访问令牌*** 回复: {"error_description":"引发了 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' 类型的异常。"} 问题是:为什么我不能使用我的访问令牌?我做错了什么? 谢谢

【问题讨论】:

    标签: access-token onedrive


    【解决方案1】:

    您的第一个示例是对 Discovery 服务的请求,如果您还不知道资源 ID,它通常用于发现资源 ID。此请求将需要使用 resourceId == 发现服务 URL 获取的令牌。从发现服务获取正确的资源 ID 后,您可以使用新的 resourceId 请求新的访问令牌。

    “问题是:为什么我不能使用我的刷新令牌?我做错了什么?”: 刷新令牌不是进行 API 调用的有效令牌,您需要 access_token。刷新令牌用于在过期时获取新的访问令牌。

    【讨论】:

    • 谢谢凯文。正如我所见,第一个例子不是最好的例子之一。我理解我的错误 - 我尝试使用我的资源中的访问令牌。我应该将访问令牌用于发现服务 URL。 “为什么我不能使用我的刷新令牌”这个问题应该是“为什么我不能使用我的访问令牌”,其余 2 个示例都是最新的。
    【解决方案2】:
    解决了! 我的请求的问题是“资源:***(我的资源)***”。 如果我想访问资源,我不能使用应用程序 ID 或客户端 ID(在我的情况下,这两个是相同的)。 我想要哪个资源 - 我需要它的令牌。我应该阅读 https://api.office.com/discovery/v2.0/me/services 可用资源列表的响应 所以 1. 使用资源“https://api.office.com/discovery/”发布 https://login.microsoftonline.com/tenant/oauth2/token 2. 从点 1 获取带有 refresh_token 的 https://api.office.com/discovery/v2.0/me/services 3. POST https://login.microsoftonline.com/tenant/oauth2/token 与资源“https://tenant-my.sharepoint.com/”在我的情况下 4.并使用第3点的刷新令牌,例如获取 https://tenant-my.sharepoint.com/_api/v2.0/me/drive/special/documents

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-07
      • 2016-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多