onedrive-api-docs: CompactToken parsing failed with error code: 80049217
Hi guys
Currently, I try to use you graph API. I’m not using you ADD authentication library (I try to implement it by using oAuth 2). Here is my issue :
- I request my authorization code and received it well
- I request my token with a post on
https://login.microsoftonline.com/common/oauth2/v2.0/token. Huuuum. Got an error:
Failed to load https://login.microsoftonline.com/common/oauth2/v2.0/token: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
Fun fact, the request trigger an error but I still received my token.
3. I send a request to https://graph.microsoft.com/v1.0/me/drive and adding my token to the headers :
headers: {
'Authorization': 'Bearer <token>'
}
Weeeeeelll. The response sends me a 401 Unauthorized and a message :
{
"error": {
"code": "InvalidAuthenticationToken",
"message": "CompactToken parsing failed with error code: 80049217",
"innerError": {
"request-id": "5f98f27a-50ba-4ace-963b-60905bf4207c",
"date": "2018-01-29T16:59:44"
}
}
}
Hum. I check the authorization in the header request :
Authorization:Bearer <token>
Weeeeeell. Actually. I’m lost. Can you help me?
Thanks,
SLedunois
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 26
- Comments: 73 (2 by maintainers)
Maybe it sounds stupid but double check:
When requesting the token you get an JSON object in response. This object contains properties like expires_in, token_type and access_token.
When adding the Authorization: Bearer <token> to your request, you should replace <token> only with the access_token and not the entire object
I solved my issue by:
@suparnavg I’m reopening the issue.
Try setting “resource” param when requesting the access token for the API.
You can find it “subtle” in the documentation (only within the example code):
https://developer.microsoft.com/en-us/graph/docs/concepts/rest
-> &resource=https%3A%2F%2Fgraph.microsoft.com%2F
I’m facing the same issue, like this response:
Can this issue be reopened please? Otherwise I’ll open another one (not the smartest choice, but…).
I am facing this error while using Graph APIs. And the worse part is the APIs work just fine most of the times, but intermittently return this error.
Has anyone really found a solution for random/intermittent error returned by Graph APIs?
@suparnavg Can you please post the exact response? Below I’ll clarify my scenario as much as I can, pardon me for the loooong answer.
My scenario is as follows: I want to authenticate users with Azure AD and read the profile of the authenticated user (only that user).
First of all, I authenticate users using the Azure AD oauth2 endpoint. I’m using the openid strategy, and I’m asking for both the id_token and the authorization code at once, by visiting the following URL:
https://login.microsoftonline.com/MY_TENANT_ID/oauth2/authorize?scope=openid&response_type=code+id_token&client_id=MY_AZURE_APP_ID&nonce=A_RANDOM_HASH&state=ANOTHER_RANDOM_HASH&response_mode=form_post&redirect_uri=MY_APP_REDIRECT_URI
Note: all the UPPERCASE words must be replaced with actual values.
This URL pops up the Microsoft login prompt and, upon success, it redirects to the <MY_APP_REDIRECT_URI> URL with the following parameters in POST:
At this point, if the id_token passes JWT validation, the user is authenticated-so if all you need is the id_token, you’re done.
But, I want to access the MS Graph API too, and to do so I need an access token which I can obtain by POSTing the following parameters to the token URL ( https://login.microsoftonline.com/MY_TENANT_ID/oauth2/token )
The reply should be a JSON object containing the keys:
Now I can access the Graph API, to get more information about the logged in user, by taking the returned access_token and making the following HTTP request:
Hi there!
I’ve been working with access tokens for couple of weeks now. I’m kinda new to this but I’ve found this link that helped me solve the issue with error “message”: “CompactToken parsing failed with error code: 80049217” https://contentanalytics.digital.accenture.com/pages/viewpage.action?pageId=685015085
The problem was in syntax when calling the service…it requires “space” between “Bearer” and the token you’re using. You can do it like "Bearer " + token or as its shown on the link.
Might be late but I hope this helps!
@paolostefan thanks for the detailed answer
I am following the exact same steps as you, and my API calls are working fine (Calendar, Contacts, etc. all good) - except for OneDrive calls. I have included the Files.ReadWrite.All scope while registering the app, so invalid scopes should not be causing the problem.
While making the OneDrive API call, I use my existing refresh token to generate a new access token, then send a GET to this uri: “‘https://graph.microsoft.com/v1.0/me/drive/root/children’” - which returns the error
I had this same issue, so, I checked the AccessToken and it looked unusual (for Microsoft)… Like with many dashes and etc…
Hence, I went back and checked all the details only to find a simple error with the endpoint url for auth and token.
The https://graph.microsoft.com/oidc/userinfo endpoint only works with v2.0 of Auth and Token endpoints: https://login.microsoftonline.com/common/oauth2/v2.0/authorize https://login.microsoftonline.com/common/oauth2/v2.0/token
That fixed it for me.
Obviously this error is occurring when the token is malformed. In my case it was malformed, because i was using postman. In the authentication tab just enter the token not the string "Bearer " in front of it.
OK I feel really stupid right now. But my issue was the same as @Klervix . I had my token in database and it was getting truncated because JWT is a lot longer than your usual access token that you get from other services like Google or Facebook. I kept on thinking why is everyone talking about JWT when I have a very short token in database.
I experienced this error when keeping the token in a small variable. Make sure to use the complete token (mine finished with ‘…’).
I got this error code when sending the
<token>part of the above as bytes rather than a utf-8 decoded string, so maybe check that?@1terahertz
OneDrive authentication and sign-in: That’s endpoint is authorizing an application to use a Microsoft account for personal OneDrive. I tried to use it with my Onedrive Business account, it didn’t work. You should follow the authorization process in Authorization and sign-in for OneDrive in Microsoft Graph, it’s supports both personal and business accounts.
The
onedrive.appfolderoronedrive.readwritepermission scope when getting an access token is necessary.You also need to activate the
Files.ReadWrite.AppFolderpermission on the menuAPI permissions(Delegated permissions) in your portal Azure app.Note: If a request is made without the permission(s) (
user.readoropenidpermission scope is important), that error will be returned.Like TruongDuyIT hinted, the request (
acquireToken() / get https://graph.microsoft.com/v1.0/me/drive…) must include the scopes (permissions) for the token to be accepted. For example, if I wanted the drive files (as in the request above), I must send the scope (https://graph.microsoft.com/)Files.Read (or related). But if a request is made without the appropriate permission(s), that error will be returned.Like TruongDuyIT hinted, the request (
acquireToken() / get https://graph.microsoft.com/v1.0/me/drive…) must include the scope(s) (permissions) for the token to be accepted. For example, if I wanted the drive files (as in the request above), I must send the scope (https://graph.microsoft.com/)Files.Read (or related). But if a request is made without the permission(s), that error will be returned.Hi,
I also had the same problem, in my case I tried to authenticate against microsoft graph api from prowershell using oauth2 and in the headers it indicated this:
So it indicated to the destination that the URL was encoded (it had to decode it to read it), but this was not true, I was not coding anything and the client secret had special characters that disappeared when they were decoded. I tried to manually code the client secret through this page and it worked!
Hello guys, I was banging my head against the wall with the same issue, but managed to solve it (at least for me!). The issue was with the Authorization header, if the header looks like this: “Bearer: {token}”, I got the error, but if I changed the header to “Bearer {token}” (removed the '😂, it works.