Microsoft OneDrive API InvalidAuthenticationToken CompactToken parsing failed with error code: -2147184105

I have looked at the two similar questions in StackoverFlow and on the web but I still don't understand what I should do.

I want to download a file that is located on OneDrive programmatically using a bash script (with curl).

So I've seen here that I can use the code flow to access Microsoft Graph. So I proceeded like that (I inspired myself from the Jay Lee answer):

1- I get the code with this URL https://login.live.com/oauth20_authorize.srf?client_id=10c492f9-132a-4079-adae-382dad9d4339&scope=onedrive.readonly&response_type=code&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient

2- Then I swap authorization code for access token with this URL: curl -X POST https://login.live.com/oauth20_token.srf -d "client_id=${client_id}&redirect_uri=${redirect_uri}&code=${auth_code}&grant_type=authorization_code" --header "Content-Type:application/x-www-form-urlencoded"

And I store the token and the expire time in a file

3- I made some process to handle the fact that I have to refresh the token (according to the expire time).

4- I use my token to download my file programmatically with Microsoft Graph

api_data=$(curl https://graph.microsoft.com/v1.0/me/drive/items/B8D9948257F95B84%21104/content -H "Authorization: Bearer $access_token") echo -e "$api_data"

The problem- When I run the program, I get this:

enter image description here

How come?

Upvotes: 1

Views: 2923

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33094

You're authenticating against the wrong endpoint. The login.live.com endpoint cannot provide a valid token for Graph. You need to use the v2 Endpoint for this instead.

Check out Microsoft v2 Endpoint Primer for a walkthrough. Given that you're using curl, the pseudo code provided should give you everything you need.

Upvotes: 3

Related Questions