I'm integrating onedrive to my application to get files in users onedrive. I created an application in https://apps.dev.microsoft.com/#/appList. Following is the url to get the sign in window and get user authentication.
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={clientID}&scope=Files.ReadWrite.All offline_access&response_type=code&redirect_uri=http://localhost:8080/onedrive/code
The onedrive passes the code and I'm capturing that and using the following request I can get the access_token and refresh_token too.
POST https://login.microsoftonline.com/common/oauth2/v2.0/token
client_id={client_id}&redirect_uri=http://localhost:8080/onedrive/code&client_secret={client_secret}&code={code}&grant_type=authorization_code
Then I store the refresh token in my DB.
Later, When I want to get files in users onedrive, I send my refresh+token and get an access_toke like the following.
POST https://login.microsoftonline.com/common/oauth2/v2.0/token
client_id=client_id}&redirect_uri=http://localhost:8080/onedrive/code&client_secret={client_secret}&&refresh_token=&refresh_token_stored_in_db}&grant_type=refresh_token
I get the access token from the above and use it to get the list of files in user onedrive like following. (Is this the correct API to call?)
GET https://api.onedrive.com/v1.0/drive/root/children
Authorization: bearer {access_token}
The problem is in this process. The response is,
{"error":{"code":"unauthenticated","message":"Authentication failed"}}
Can someone please tell me what is the problem in my code. Thanks in advance.