C# OneDrive upload client error CompactToken parsing failed with error code: 80049217

iz111 86 Reputation points

I successfuly got access token for OneDrive. But when i try to upload a file i got following error:

Code: InvalidAuthenticationToken

Message: CompactToken parsing failed with error code: 80049217

Note that same code always works on my development machine, on two other machines i also got access token but always fail on upload.

Scopes: "user.read", "Files.ReadWrite", "offline_access"

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
915 questions
A Microsoft file hosting and synchronization service.
187 questions
Microsoft Graph Permissions API
Microsoft Graph Files API
Microsoft Graph Files API
A Microsoft API to create an app that connects with files across OneDrive, OneDrive for Business, and SharePoint document libraries.
326 questions
No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 20,956 Reputation points

    Hi @iz111

    When you get an access token, it is actually an object that contains JSON key-value pairs, and you only need to pass the Token value. So please change your code to:

    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accesstoken.Token);

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Sayantan Ganguly-MSFT 765 Reputation points Microsoft Vendor

    Hello iz111,

    Thanks for reaching out!

    This error message "CompactToken parsing failed with error code: 80049217" generally occurs when the token used is invalid.

    Please refer to the similar post:

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment"

  2. iz111 86 Reputation points

    I don't understand, it is working on my development machine. I received the token.
    If token is invalid it might be something wrong with permissions or the way I ask for token?
    Following are permissions on the Azure for my app:

    Code to receive access token:

    publicClientApp = PublicClientApplicationBuilder.Create(ApplicationID)
                                                                      .WithAuthority(AzureCloudInstance.AzurePublic, "common")
    authResult = publicClientApp.AcquireTokenInteractive(scopes)

    When I do upload I pass token as follows:

    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", <accesstoken>);
    requestMessage.Version = new Version(1, 1);