User defined Managed Identity #1401
-
Hi, I am implementing an azure function to get data from SharePoint (across all sites) and using user defined managed identity. I am using graph api in general and that all seems fine, but for few operations I have to use SharePoint Rest API. I am thinking the PnP core for this scenario.I followed the help guide and examples that talks about managed identity in general and in some places it clearly mentions system assigned managed identity only. The certificate based authentication works but when I move the code to azure the pnp core is not working. It's worth mentioning that my graph api works with the user defined managed identity. Is the user defined managed identity supported to connect to SharePoint? Before I proceed too far I wanted to ensure this is a supported model. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@jagsridharan : I've never tried that myself, but in theory this should be possible. This sample (https://pnp.github.io/pnpcore/demos/Demo.AzFunction.ManagedIdentity/README.html) shows how to write a custom authentication provider (https://github.com/pnp/pnpcore/blob/dev/samples/Demo.AzFunction.ManagedIdentity/ManagedIdentityTokenProvider.cs) that handles a system managed identity. You can update this code to also use a user managed identity. Regarding certificates: this is only needed when using app-only access, SharePoint REST/CSOM calls when used via app-only do require certificate based auth. Graph calls can work with just a secret. Given PnP Core SDK requires REST it means that if you want to use app-only you'll have to use certificate based auth. |
Beta Was this translation helpful? Give feedback.
Hi @jansenbe ,
Apologies I couldn't come back earlier. I managed to get the Managed Identity work with the user-defined identity based on the sample you provided but with a bit of changes.
I followed this sample you provided, however I had to change the credential code to:
var credential = new DefaultAzureCredential();
The ChainedTokenCredential code below is not working for some reason, I may have to check this further:
If I use the DefaultAzureCredential, it is able to pick up teh Client Id using AZURE_CLIENT_ID Environment variable as discussed here.
Thank…