Replies: 4 comments
-
@erwinvanhunen maybe you can help with this? After reading a bit more, I think using access tokens would be the perfect solution for me. But I can't make it work. Here is what I tried:
What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
-
So I've found that using office 365 cli to get token, and it's working very well
Then it outputs the token in debug logs. i stored it as $accessToken. then it this code works perfectly fine
now all that i need to understand is how the oauth2 flow works with m365 cli so i can use it on my app to get the same token. |
Beta Was this translation helpful? Give feedback.
-
after a lot of thorough digging, finally cracked it. the flow is to get a refresh token and then exchange it for sharepoint token but for scope add -admin suffix to tenant. like this:
now
finally works! |
Beta Was this translation helpful? Give feedback.
-
Get-PnPTenant only worked for me when I'm connected to the admin url. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What I'm trying to do is have the admin enter their credentials on the web page (client side), then transfer the token to the backend and execute powershell commands to query their sharepoint site state. Specifically
Get-PnPTenant
I tried running:
but i get
Get-PnPTenant: The remote server returned an error: (401) Unauthorized.
So I tried a different approach, I have setup all the needed access for a single tenant, let's call it tenant1, and generated certificate for that tenant. Now I can connect perfectly fine for tenant1:
Connect-PnPOnline -Url "https://tenant1.sharepoint.com" -ClientId "xxxxxxxx-xxxx-...." -Tenant "tenant1.onmicrosoft.com" -CertificatePath cert.pfx -CertificatePassword (ConvertTo-SecureString -String "pass" -AsPlainText -Force)
However, it required running this command:
Register-PnPAzureADApp -ApplicationName appname -Tenant=tenant1.onmicrosoft.com -DeviceLogin
But this command is interactive, and I require unattended approach that works on Linux - because I run on the server side.
This is where I hit a dead end. Any help would be appreciated, specifically - Explanation how I can connect an app without user interaction. We can assume I have the admin token, or even the actual username and password of the admin.
Beta Was this translation helpful? Give feedback.
All reactions