Replies: 2 comments 6 replies
-
tried using
I just get a null object reference when calling clientContext.ExecuteQuery(); |
Beta Was this translation helpful? Give feedback.
-
Try the following: var credential = new ChainedTokenCredential(
new ManagedIdentityCredential(),
new EnvironmentCredential()
);
var scope = $@"https://{siteUri.Host}/.default";
var accessToken = await credential.GetTokenAsync(new TokenRequestContext(new[] { scope }));
var authManager = new PnP.Framework.AuthenticationManager();
var clientContext = authManager.GetAccessTokenContext(siteUri.ToString(), accessToken.Token); This will use the managed identity of the Azure Function if running in Azure and the credentials stored in environment variables if running locally from e.g. Visual Studio. For info on how to use EnvironmentCredential see EnvironmentCredential Class For more info and other credential classes to use see Azure Identity client library for .NET |
Beta Was this translation helpful? Give feedback.
-
Are there any examples of this. Is it even possible?
Beta Was this translation helpful? Give feedback.
All reactions