sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

SharePoint Online API: Access denied creating Personal Site when passing Signed In User Bearer Token

Open garrytrinder opened this issue 7 years ago • 24 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

The below HTTP call should create a new personal site for the user

POST /_vti_bin/client.svc/ProcessQuery HTTP/1.1
Host: tenant-admin.sharepoint.com
Content-Type: application/xml
Authorization: Bearer <token>

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="SharePoint PnP PowerShell Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
    <Actions>
        <ObjectPath Id="5" ObjectPathId="4" />
        <Method Name="CreatePersonalSiteEnqueueBulk" Id="6" ObjectPathId="4">
            <Parameters>
                <Parameter Type="Array">
                    <Object Type="String">[email protected]</Object>
                </Parameter>
            </Parameters>
        </Method>
    </Actions>
    <ObjectPaths>
        <StaticMethod Id="4" Name="GetProfileLoader"  TypeId="{9c42543a-91b3-4902-b2fe-14ccdefb6e2b}" />
    </ObjectPaths>
</Request>

Observed Behavior

Above request results in 200 OK response but returns the below error, no personal site is created for the user.

[
    {
        "SchemaVersion": "15.0.0.0",
        "LibraryVersion": "16.0.19318.12002",
        "ErrorInfo": {
            "ErrorMessage": "Access denied. You do not have permission to perform this action or access this resource.",
            "ErrorValue": null,
            "TraceCorrelationId": "7c05089f-70d6-1000-af48-5aaa8564ad67",
            "ErrorCode": -2147024891,
            "ErrorTypeName": "System.UnauthorizedAccessException"
        },
        "TraceCorrelationId": "7c05089f-70d6-1000-af48-5aaa8564ad67"
    }
]

Steps to Reproduce

  • Create Azure AD application
  • Set the following delegate SharePoint Online API permissions
    • AllSites.FullControl
    • User.ReadWrite.All
  • Grant Admin consent for delegated permissions
  • Generate Bearer Token using OAuth 2.0 Authorization Code Flow
    • Provide Tenant Admin credentials
  • Pass Bearer Token in Authorisation header of request

Related Issues

https://github.com/SharePoint/PnP-PowerShell/issues/2267 https://github.com/OneDrive/onedrive-api-docs/issues/530 https://github.com/pnp/office365-cli/issues/929

garrytrinder avatar Sep 23 '19 14:09 garrytrinder

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Sep 23 '19 14:09 msft-github-bot

Context please... where is the method CreatePersonalSiteEnqueueBulk coming from (ie: what API are you using), what's the environment, etc...

andrewconnell avatar Sep 26 '19 11:09 andrewconnell

The more context details you can provide, the easier it is to help assist on issues. Any code you can provide and/or screenshots of the issue also help. The easier you can make it to reproduce the issue, the easier and quicker it is for someone to help you. Things that always help posting with every issue include (1) SharePoint environment(s) (on-prem / SP 2016 / SP 2019 / SharePoint Online), (2) if SharePoint Online, is the tenant configured for standard / targeted release, (3) if SharePoint Framework, list the versions of installed tools (Node.js, NPM, Yeoman, Gulp, SPFx generator, etc... use npm list -g --depth=0), (4) if applicable, browser(s) tested, (5) if applicable, version of Office UI Fabric React & (6) anything else you can provide.

msft-github-bot avatar Sep 26 '19 11:09 msft-github-bot

Furthermore, you say “create personal site” which I think implies SharePoint, but you reference OneDrive. Hence the confusion on what you are trying to do.

Regardless, of the API, you need to ensure the API supports application permissions. It may only support delegated (app+user) permissions for auditing requirements & not app-only.

andrewconnell avatar Sep 26 '19 12:09 andrewconnell

@andrewconnell appreciate your commenting on this issue and apologies for the lack of clarity...

I am working on replicating the New-PnPPersonalSite cmdlet functionality from PnP PowerShell, which creates "Creates a personal / OneDrive For Business site", into the Office 365 CLI.

POST /_vti_bin/client.svc/ProcessQuery HTTP/1.1
Host: tenant-admin.sharepoint.com
Content-Type: application/xml
Authorization: Bearer <token>

<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="SharePoint PnP PowerShell Library" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
    <Actions>
        <ObjectPath Id="5" ObjectPathId="4" />
        <Method Name="CreatePersonalSiteEnqueueBulk" Id="6" ObjectPathId="4">
            <Parameters>
                <Parameter Type="Array">
                    <Object Type="String">[email protected]</Object>
                </Parameter>
            </Parameters>
        </Method>
    </Actions>
    <ObjectPaths>
        <StaticMethod Id="4" Name="GetProfileLoader"  TypeId="{9c42543a-91b3-4902-b2fe-14ccdefb6e2b}" />
    </ObjectPaths>
</Request>

However this returns the below 200 OK response

[
    {
        "SchemaVersion": "15.0.0.0",
        "LibraryVersion": "16.0.19318.12002",
        "ErrorInfo": {
            "ErrorMessage": "Access denied. You do not have permission to perform this action or access this resource.",
            "ErrorValue": null,
            "TraceCorrelationId": "7c05089f-70d6-1000-af48-5aaa8564ad67",
            "ErrorCode": -2147024891,
            "ErrorTypeName": "System.UnauthorizedAccessException"
        },
        "TraceCorrelationId": "7c05089f-70d6-1000-af48-5aaa8564ad67"
    }
]

The app used to generate the bearer token only uses delegate permissions for SharePoint Online (the common Office 365 CLI app identity) so no app-only calls here to SharePoint.

Further investigation into the PnP-PowerShell cmdlet also showed that the cmdlet only worked when authenticating with SharePoint Online by passing username and password (Forms Based Auth) as the same error is thrown when using a Bearer Token.

garrytrinder avatar Sep 26 '19 15:09 garrytrinder

@garrytrinder said

I am working on replicating the New-PnPPersonalSite cmdlet functionality from PnP PowerShell, which creates "Creates a personal / OneDrive For Business site", into the Office 365 CLI.

That's not correct... the PnP cmdlets do not interact with the O365 CLI. The O365 CLI is an alternative to the POSH cmdlets. Both are using public REST APIs in SharePoint / Office 365 to do their work. I think what you wrote is a typo.

If you have specific questions about the PNP cmdlets, you should post those to the github project for the PnP POSH project, not here, as that's the more relevant place.

The underlying question I'm tracking down with SP engineering is "is app only supported for this task"... will follow up if I get an answer.

andrewconnell avatar Sep 26 '19 16:09 andrewconnell

That's not correct... the PnP cmdlets do not interact with the O365 CLI. The O365 CLI is an alternative to the POSH cmdlets. Both are using public REST APIs in SharePoint / Office 365 to do their work. I think what you wrote is a typo.

This is not a typo, I am well aware of the difference between the two libraries and I am not trying to make them interact.

I am contributing to the Office 365 CLI project, not PnP PowerShell. The contribution refers to replicating the "functionality" of the New-PnPPersonalSite cmdlet.

A new command, spo personalsite add has been designed and proposed for this, it is using the public REST API to create a new personal site. (Ref: https://github.com/pnp/office365-cli/issues/929).

If you have specific questions about the PNP cmdlets, you should post those to the github project for the PnP POSH project, not here, as that's the more relevant place.

I already have and raised this as an issue, which I have referenced (Ref: https://github.com/SharePoint/PnP-PowerShell/issues/2267)

The point I am trying to raise is that the same underlying API call is reacting in the same way when when passing a bearer token in the authorisation header, whether that is using delegated (the signed in user) or application permissions (without signed in user).

I have updated the issue title, description and steps to reproduce to make this clearer, as I think I caused the confusion by getting my terminology wrong in the first place 🤦🏻‍♂️.

I appreciate you responding to this issue 👍🏻

garrytrinder avatar Sep 26 '19 17:09 garrytrinder

@garrytrinder Gotcha... my bad as I didn't read your comment about the CLI correctly. I thought you were saying POSH was using the CLI... I didn't get you were trying to replicate functionality from POSH cmdlet => CLI.

At any rate, I've ping'd someone in engineering who's looking into it. I can't answer it so waiting on what the find out & when there's something to report, I'll do that.

andrewconnell avatar Sep 29 '19 14:09 andrewconnell

Hey @andrewconnell any update from engineering on this?

garrytrinder avatar Mar 10 '20 00:03 garrytrinder

Ping @andrewconnell, any update on this issue?

waldekmastykarz avatar Jun 05 '20 17:06 waldekmastykarz

Ah apologies, I meant to raise this with the team directly after speaking with @andrewconnell but didn't get around to it. It's with me @waldekmastykarz

garrytrinder avatar Jun 05 '20 18:06 garrytrinder

Hi, can you use a Bearer Token with Sharepoint Online? https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread FAQ Can I use other means besides certificates for realizing app-only access for my Azure AD app? No, all other options are blocked by SharePoint Online and will result in an Access Denied message.

RyanSmith-00 avatar Jun 08 '20 17:06 RyanSmith-00

Turns out my issue with Access Denied was the API permissions. For Sharepoint Online Lists I needed to add Application permissions to the Microsoft Graph | Sites.Read.All

Sites Read All

RyanSmith-00 avatar Jun 10 '20 14:06 RyanSmith-00

@garrytrinder, is there an update on this issue?

mbuergi avatar Nov 18 '20 09:11 mbuergi

Is there any update on this? We want to automate PersonalSite creation using the Azure AD app within Automation Runbook and currently looking into workaround solution.

clientbala avatar Jan 08 '21 16:01 clientbala

Any updates on this? Or workaround?

emi662002 avatar Jan 20 '21 08:01 emi662002

Is there any update on this? We want to automate PersonalSite creation using the Azure AD app within Automation Runbook and currently looking into workaround solution.

@clientbala did you find a workaround for this ?

emi662002 avatar Jan 20 '21 08:01 emi662002

Apologies for the delay on updating, unfortunately I have been unable to ascertain whether this is supported through the REST API using a Bearer token with delegate permissions.

garrytrinder avatar Jan 22 '21 10:01 garrytrinder

I landed here after having the same issue when using Request-PnPPersonalSite and New-PnPPersonalSite, both returning 403 Access Denied. I had been connecting with Connect-PnPOnline -Url <mysite> -Credentials <mycreds> But just now I connected with Connect-PnPOnline -Url <mysite> -UseWebLogin And this time around, Request-PnPPersonalSite worked with no error! Though I've yet to verify the site is being created.

klennan avatar Aug 25 '21 14:08 klennan

Any update on this? Since ASC will be retired for SharePoint we'll have to use an Entra App Registration. But that still doesn't seem to work...

rjansen-rocnova avatar Feb 13 '25 09:02 rjansen-rocnova