简体   繁体   English

Microsoft Graph API 身份验证 - 访问令牌为空

[英]Microsoft Graph API Authentication - Access token is empty

I'm trying to get a bearer token to upload a file to Microsoft Teams.我正在尝试获取不记名令牌以将文件上传到 Microsoft Teams。 When doing a post request to当做一个发布请求时

https://graph.microsoft.com/{tenantId)/oauth2/v2.0/token
body: 
    client_id, 
    scope= https://graph.microsoft.com/.default, 
    grant_type= authorization_code, 
    client_secret & redirect uri (https://myenvironment.com/callback)

code : I got this by doing a request to代码:我通过请求得到这个

https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/authorize?client_id={client_id}&response_type=code&redirect_uri={redirect_uri}&response_mode=query&scope=https://graph.microsoft.com/.default

I get a 401 Unauthorized with error code InvalidAuthenticationToken and error message Access token is empty .我收到 401 Unauthorized 错误代码InvalidAuthenticationToken和错误消息Access token is empty

I'm not sure which api you wanna call here, but I can show you an example.我不确定你想在这里调用哪个 api,但我可以给你看一个例子。 For instance, I want to call this api to upload a file on behalf of me.例如,我想调用这个 api来代表我上传文件。

Then I need to give api permission for calling this api, you can see api permission here.然后我需要给api权限来调用这个api,你可以在这里看到api权限。

在此处输入图像描述

Then open the browser to send a request like this然后打开浏览器发送这样的请求

https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/authorize?
client_id=client_id
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost:8080%2F
&response_mode=query
&scope=Files.ReadWrite Files.ReadWrite.All Sites.ReadWrite.All
&state=12345

Then you will get a code in the url, then cope the code.然后你会在url中得到一个code,然后应对code。

Post: https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token

request header
Content-Type:application/x-www-form-urlencoded

request body
client_id:
client_secret:
code: copy_from_browser_url
redirect_uri:http://localhost:8080/
grant_type:authorization_code
scope:Files.ReadWrite Files.ReadWrite.All Sites.ReadWrite.All

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM