Skip to content

Instantly share code, notes, and snippets.

@BrianTJackett
Last active October 7, 2019 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BrianTJackett/3c629bca714325440cffce73e6b3bf56 to your computer and use it in GitHub Desktop.
Save BrianTJackett/3c629bca714325440cffce73e6b3bf56 to your computer and use it in GitHub Desktop.
Microsoft Graph C# .Net Core prepare GraphServiceClient
var clientId = "<AzureADAppClientId>";
var clientSecret = "<AzureADAppClientSecret>";
var redirectUri = "<AzureADAppRedirectUri>";
var authority = "https://login.microsoftonline.com/<AzureADAppTenantId>/v2.0";
var cca = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority(authority)
.WithRedirectUri(redirectUri)
.WithClientSecret(clientSecret)
.Build();
// use the default permissions assigned from within the Azure AD app registration portal
List<string> scopes = new List<string>();
scopes.Add("https://graph.microsoft.com/.default");
var authenticationProvider = new MsalAuthenticationProvider(cca, scopes.ToArray());
GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment