I'm doing Office365 account-based login functionality through SharePoint on PHP.
After doing that I was able to login and get the SPAppToken and SPSiteUrl I use them to get the refreshToken, then I get the accessToken based on the refreshToken

Continue to trying to get the information of the logged in user but failed. Information is as follows:

URL: https://mypage.sharepoint.com/_api/web/currentuser
Method: GET
Accept: application/json; odata=verbose
Authorization: Bearer + accessToken


     "error": {
         "code": "-2147024891, System.UnauthorizedAccessException",
         "message": {
             "lang": "ja-JP",
             "value": "Attempted to perform an unauthorized operation."

I don't know what to do to be able to get my own credentials API, please help, I think I need somewhere to give permission, but I don't know where it is! Thanks everyone!

  • Is this user having permissions on the respective SharePoint site? Commented Dec 7, 2022 at 7:49
  • @GaneshSanap yes! the account I'm testing with has permissions "Full control" Commented Dec 7, 2022 at 7:55

1 Answer 1


I already know my cause!
Because I have not given permission for my login Add-In to create.

I did step 1, but not done step 2

Step 1:

Go to the URL and create the Add-in.
Copy Client Id and Client Secret. And click button Create https://mypage.sharepoint.com/_layouts/15/appregnew.aspx

enter image description here

Step: 2 Go to the URL:

Paste Client Id to App Id And paste XML:

<AppPermissionRequests AllowAppOnlyPolicy="true">
    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Read" />

Click button Create enter image description here

Continue click Trust It and Done

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.