Forum Discussion
Tommy-Johannessen
Aug 25, 2023Copper Contributor
Error when authenticating with Default Azure Credential (CSOM)
Before the summer break I used a code that we have developed to set up content on SharePoint sites though local host when running from Visual Studio. Then when I returned about a week later the code ...
- Oct 23, 2023then you will have to wait for MS reenabling SPO accepting 'user_impersonation' scope (there is a ticket already) 🙂
any other solution involves an app registration created
elnurrr
Oct 20, 2023Copper Contributor
Perneel, here is your workaround 🙂
#if DEBUG
var credential = new InteractiveBrowserCredential(new InteractiveBrowserCredentialOptions() { ClientId = "the-client-id" });
#else
var credential = new Azure.Identity.DefaultAzureCredential();
#endif
var token = await credential.GetTokenAsync(new Azure.Core.TokenRequestContext(new[] { "https://yourtenanthere.sharepoint.com/.default" }));
log.LogInformation(token.Token);
The app registration the 'the-client-id' refers to looks like this
As a result, you are able to get an access token via the the Authorization Code Flow with PKCE and your browser while debugging your code locally in VS