I am trying to get OAuth code to access sites and lists from SharePoint Online. Below are the steps that I have performed:
- Register application at URL https://adventurer.sharepoint.com/_layouts/15/appregnew.aspx
- Generate Client ID and Secret at above URL and create the application.
- Request OAuth code from user's credentials by accessing below URL:
https://adventurer.sharepoint.com/_layouts/15/OAuthAuthorize.aspx?client_id=ebd57c66-97dd-498d-83f5-eedd6536bbc2&scope=Web.Read List.Write &response_type=code&redirect_uri=https://localhost/SharePointOnlineSample
After authentication from SharePoint server, I get error as "access_denied". I don't know what is causing this issue. If I remove the scope from above URL and grant permission to application using below URL:
and below XML:
<AppPermissionRequests AllowAppOnlyPolicy="true"> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" /> </AppPermissionRequests>
It works just fine. But I want to know the correct approach. Why is this XML required to grant permission? Why can't I just get OAuth code using scope in request URL?