If you are using Azure DevOps pipelines with Service Connections, you may have noticed a mysterious blue dot next to your service connection name
...
For further actions, you may consider blocking this person and/or reporting abuse
Before trying to use this to deploy spfx read: github.com/pnp/powershell/issues/3...
and be aware that officially only certificate auth is supported: learn.microsoft.com/en-us/sharepoi...
in any case great post and thanks for sharing. Hope Microsoft will take a look on this.
This is the ticket I opened myself, and I see you are linking to your own reply. I'm not done with this ticket yet, and I hope the PnP team is working in it.
I don't find replies form Jake very helpful, as they're just "mudding the waters", but... he admits himself that refreshing the token works with his old app registrations.
What I'm describing is not authenticating, but rather using of already authenticated identity. I'm running my code in a pipeline, in a context of already authenticated service principal, and I'm refreshing a token that already exists to exchange Azure/Graph token for a SPO token. The idea itself is not new and you can use it with service principals that you created yourself.
This token refresh works and I'd like to have this "rewrite" supported by
Connect-PnPOnlinenatively. This is what this ticket is about.regarding your problem...
The key here is to make sure that the Service Principal has correct API permissions to execute. I see you write "I could connect and read web props using the access token but, as soon as i try to install spfx solution I get the "The remote server returned an error: (401) Unauthorized."."
Please note that authentication and authorization are two different things. You get "unauthorized". It looks like you managed to refresh the token correctly, otherwise you wouldn't be able to read the web properties in the first place and you would be getting another error message.
I haven't seen your code and I don't know which libraries you are using. What I know, however, is that PnP is using different endpoints to execute different actions, and you need to make sure that your service principal has API Permissions for both, Graph and SharePoint APIs.
I am using the above approach to deploy my spfx solutions to app catalog, and it works just fine. The above example shows creating items for simplicity, but in my environment, it's app deployment.
I'm therefore 100% sure it works
If you want to check your code gradually, i'd suggest the following:
I wanted to address a missing piece of information that might help anyone encountering a similar issue 😊 First off, I want to express my gratitude for your post as it led me to discover what I believe is the most effective method for connecting pipelines to the Microsoft 365 ecosystem. I realize I should've expressed my gratitude in my previous comment rather than in the GitHub issue (but it was really late in day 💤).
In my case, I utilized the Sites.FullControl.All permissions for both Graph and SharePoint APIs, along with AppCatalog.ReadWrite.All for testing purposes (global app catalog). And Get-PnPWeb functions smoothly with your approach and my configuration. However, I consistently encountered a "(401) Unauthorized" error as soon as the code reached the Add-PnPApp section (the only different line from your example). Interestingly, a previous app registration with identical permissions (but using a pfx+password) was functioning correctly. This led me to suspect that the issue lies with the access token generated from WIF versus certificate authentication or that some Microsoft endpoints does not support this kind of auth (very feasible for me - and could be different across tenants), though I'm not entirely certain.
A friend of mine once told me that things we write sound "harder" compared to if we said them, and I think she is right. I really hope you didn't feel scolded by my answer. Was not my intention.
It bothers me a lot that the deployment doesn't work for you. I just updated my script to deploy an app to the tenant-level app catalog and documented each step: Deploy SPFx app using pipeline's Workload Identity federation. And.. it works 🤷♀️One think that comes to my mind is that maybe you have to wait? (see the last section of the post referenced).