Is there any way to authenticate an application with SharePoint rest API like Graph API using Client ID and Client Secret? I wanna use SharePoint rest API in my console application.
Asked
Active
Viewed 577 times
1 Answers
1
This works for me:
In Azure Active Directory I have configured permissions for SharePoint API.
In my code I have scopes defined this way:
var scopes = new [] {"https://<tenantName>.sharepoint.com/allsites.manage"};
var clientApp = ConfidentialClientApplicationBuilder.Create($"{clientId}")
.WithAuthority($"https://login.microsoftonline.com/{tenantId}")
.WithClientSecret($"{clientSecret}").Build();
// acquire a token for the app
AuthenticationResult result = null;
try
{
result = await clientApp.AcquireTokenForClient(scopes)
.ExecuteAsync();
}
catch (MsalUiRequiredException ex)
{
...
}
catch (MsalServiceException ex)
{
...
}

user2250152
- 14,658
- 4
- 33
- 57
-
I tried the above code, It returns an exception Invalid Scope. How to overcome this exception and How to create a request to get all sites in my tenant? Need your help @user2250152 – Nithish Kumar Apr 27 '21 at 02:23