401 Unathorized when using Connect-PnPOnline with OAuth2 token #2718
Unanswered
JackWrighty
asked this question in
Q&A
Replies: 1 comment
-
I'm having the same problem. If I connect with my own account, I can upload/download files from Sharepoint. After I successfully connect with the App Registration account, we get the following error when trying to upload a file:
I started the account off with the Sites.Selected graph API permission, but I upped it to Sites.FullControl.All and still the same error. Deleted the app account and started over and still the same. Very frustrating! Did you ever find a solution? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
I've been trying to connect to our sharepoint tenant to pull data using the Connect-PnPOnline command but I can't seem to get it to connect,
I'm using an Azure AD App Client ID & Secret to collect an OAuthToken, which I then use to connect to MS Graph and pull data, for this I Used Connect-MgGraph and Get-MgUser etc, so I know the token works.
Token collection:
$Body = @{ Grant_Type = "client_credentials" Resource = "https://graph.microsoft.com" Client_Id = "client_ID" Client_Secret = "Client_Secret" } $Oauth_Token = Invoke-RestMethod -Method Post -Uri "https://login.microsoft.com/tenant/oauth2/token?api-version=1.0" -Body $Body
When I try to use this same token to connect to PnPOnline I get 401
Connection:
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com/" -AccessToken $Oauth_Token.access_token -ValidateConnection
Error:
Connect-PnPOnline : The remote server returned an error: (401) Unauthorized.
I've given the Azure AD App a lot of API permissions, I don't think I've missed any required.

But the 401 suggests insufficient permissions, what am I missing?
Any help or advice would be appreciated, really stuck on this and going in circles on my research.
Beta Was this translation helpful? Give feedback.
All reactions