Moved from Windows Dev Center Forum
Hello,
I am developing native app: C++ with HTTP so please don't suggest .NET or JavaScript libraries :) The app should access SharePoint Online. I used to use X-Forms-Auth and "FedAuth" cookie but now need to migrate to OAuth.
1) I have registered the app in azure portal (got secret, marked redirect URI, added read/write permissions for SharePoint)
2) Then I perform OAuth flow by opening browser with
https://login.microsoftonline.com/common/oauth2/authorize
?client_id=
&response_type=code
&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
&resource=https://testorg.sharepoint.com/
it redirects to my redirect URI and I parse out the code, as expected. Then I do
POST https://login.microsoftonline.com/b51447fd-f997-4080-bf24-833070bc14bd/oauth2/token
client_id=
&client_secret=
&grant_type=authorization_code
&redirect_uri=https://login.microsoftonline.com/common/oauth2/nativeclient
&resource=https://testorg.sharepoint.com/
&response_mode=form_post
&code=
this also returns the expected JSON from where I get "access_token".
3) Later I call any SharePoint/WebDav API (e.g. SOAP UserGroup.asmx/GetCurrentUserInfo, Webs.asmx/WebUrlFromPageUrl) on https://testorg.sharepoint.com with the obtained token in auth header (Authorization:Bearer ) but get 401. However, all works fine when I follow X-Forms-Auth.
Here are permissions from
JWT:
AllSites.Manage MyFiles.Read MyFiles.Write TermStore.Read.All TermStore.ReadWrite.All User.Read User.Read.All User.ReadWrite.All

Can anyone help me here, please?
PS: I was advised to ask under SharePoint Online product but there is no such product here