简体   繁体   中英

Getting 401 Unauthorized Error : Microsoft Graph APIs

On making Rest call to Microsoft Graph API for creating groups and team, I am getting 401 unauthorized error thru my java code. Although with the same access token I am able to create the same via postman, cross checked the scope, all looks fine. Please help.

Below is the error message received:

"errorMessage": "401 Unauthorized: [{\r\n \"error\": {\r\n
\"code\": \"InvalidAuthenticationToken\",\r\n \"message\": \"Access token validation failure.\",\r\n \"innerError\": {\r\n
\"date\": \"2020-06-12T11:49:22\",\r\n \"request-id\": \"7988bd2e-3274-49e7-8c00-aa52094eab99\"\r\n }\r\n }\r\n}]"

If you're sure it is the exact same token (copying the value out of the debugger when running your code and using it in Postman), then there's some issue with how your app is adding the token to requests. This can happen if you're not forming your Authorization header correctly. It should be formed like:

Authorization: Bearer <token>

Things to look for:

  • Not putting Bearer in front of the token
  • Not including a single space between Bearer and the token
  • Not including the entire token for some reason (truncating the value, etc.)

You should also verify what's going over the wire using Fiddler or some similar program to capture the requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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