A repository of code snippets that use Microsoft Graph to perform common tasks such as sending email, managing groups, and other activities from an ASP.NET Core MVC app. This sample uses the Microsoft Graph .NET Client Library to work with data, and the Microsoft Identity Web Library for authentication on the Microsoft identity platform v2.0 endpoint.
C#
195
71 commits
updated May 23, 2024
page_type: sample products:
This sample project provides a repository of code snippets that use the Microsoft Graph to perform common tasks, such as sending email, managing groups, and other activities from within an ASP.NET Core MVC app. It uses the Microsoft Graph .NET Client SDK to work with data returned by the Microsoft Graph.
The sample uses the Microsoft Identity Web library for authentication. This library provides features for working with the Microsoft identity platform (v2.0), which enables developers to write a single auth flow that handles authentication for both work or school (Azure Active Directory) and personal (Microsoft) accounts.
In addition, the sample shows how to request tokens incrementally. Users consent to an initial set of permission scopes during sign in, but can consent to other scopes later. In the case of this sample, any valid user can sign in, but admininstrators can later consent to the admin-level scopes required for certain operations.
The Microsoft Identity Web library is in preview. Please review the support SLA before taking a dependency on this library in production code.
This sample requires the following:
Open a browser and navigate to the Azure Active Directory admin center. Login using a personal account (aka: Microsoft Account) or Work or School Account.
Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.
Select New registration. On the Register an application page, set the values as follows.
ASP.NET Core Graph Snippets App.Web and set the value to https://localhost:5001/.Select Register. On the ASP.NET Core Graph Snippets App page, copy the value of the Application (client) ID and save it, you will need it in the next step.
Select Authentication under Manage. Under Redirect URIs add a URI with the value https://localhost:5001/signin-oidc.
Set the Logout URL to https://localhost:5001/signout-oidc.
Locate the Implicit grant section and enable ID tokens. Select Save.
Select Certificates & secrets under Manage. Select the New client secret button. Enter a value in Description and select one of the options for Expires and select Add.
Copy the client secret value before you leave this page. You will need it in the next step.
IMPORTANT: This client secret is never shown again, so make sure you copy it now.
Open your command-line interface (CLI) in the ./SnippetsApp directory and run the following command to restore dependencies.
dotnet restore
Run the following commands to add your application ID and secret into the .NET Secret Manager. The Secret Manager is for development purposes only, production apps should use a trusted secret manager for storing secrets. Replace YOUR_APP_ID with your application ID, and YOUR_APP_SECRET with your application secret.
dotnet user-secrets init
dotnet user-secrets set "AzureAd:ClientId" "YOUR_APP_ID"
dotnet user-secrets set "AzureAd:ClientSecret" "YOUR_APP_SECRET"
Run the sample:
dotnet runSign in with your personal account (MSA) or your work or school account, and grant the requested permissions.
Choose a snippets category in the navigation bar, such as Users, Files, or Mail.
NOTE: If you logged in with a personal account, snippets that aren't supported for Microsoft accounts are removed from the navigation bar.
This sample creates, updates, and deletes entities and data (such as users or files). Depending on how you use it, you might edit or delete actual entities and data and leave data artifacts.
To use the sample without modifying your actual account data, be sure to perform update and delete operations only on entities that are created by the sample.
We'd love to get your feedback about this sample. You can send us your questions and suggestions in the Issues section of this repository.
Your feedback is important to us. Connect with us on Stack Overflow. Tag your questions with [MicrosoftGraph].
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Copyright (c) 2020 Microsoft. All rights reserved.
C#
70.1%
HTML
29.0%
A repository of code snippets that use Microsoft Graph to perform common tasks such as sending email, managing groups, and other activities from an ASP.NET Core MVC app. This sample uses the Microsoft Graph .NET Client Library to work with data, and the Microsoft Identity Web Library for authentication on the Microsoft identity platform v2.0 endpoint.
C#
195
71 commits
updated May 23, 2024
page_type: sample products:
This sample project provides a repository of code snippets that use the Microsoft Graph to perform common tasks, such as sending email, managing groups, and other activities from within an ASP.NET Core MVC app. It uses the Microsoft Graph .NET Client SDK to work with data returned by the Microsoft Graph.
The sample uses the Microsoft Identity Web library for authentication. This library provides features for working with the Microsoft identity platform (v2.0), which enables developers to write a single auth flow that handles authentication for both work or school (Azure Active Directory) and personal (Microsoft) accounts.
In addition, the sample shows how to request tokens incrementally. Users consent to an initial set of permission scopes during sign in, but can consent to other scopes later. In the case of this sample, any valid user can sign in, but admininstrators can later consent to the admin-level scopes required for certain operations.
The Microsoft Identity Web library is in preview. Please review the support SLA before taking a dependency on this library in production code.
This sample requires the following:
Open a browser and navigate to the Azure Active Directory admin center. Login using a personal account (aka: Microsoft Account) or Work or School Account.
Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.
Select New registration. On the Register an application page, set the values as follows.
ASP.NET Core Graph Snippets App.Web and set the value to https://localhost:5001/.Select Register. On the ASP.NET Core Graph Snippets App page, copy the value of the Application (client) ID and save it, you will need it in the next step.
Select Authentication under Manage. Under Redirect URIs add a URI with the value https://localhost:5001/signin-oidc.
Set the Logout URL to https://localhost:5001/signout-oidc.
Locate the Implicit grant section and enable ID tokens. Select Save.
Select Certificates & secrets under Manage. Select the New client secret button. Enter a value in Description and select one of the options for Expires and select Add.
Copy the client secret value before you leave this page. You will need it in the next step.
IMPORTANT: This client secret is never shown again, so make sure you copy it now.
Open your command-line interface (CLI) in the ./SnippetsApp directory and run the following command to restore dependencies.
dotnet restore
Run the following commands to add your application ID and secret into the .NET Secret Manager. The Secret Manager is for development purposes only, production apps should use a trusted secret manager for storing secrets. Replace YOUR_APP_ID with your application ID, and YOUR_APP_SECRET with your application secret.
dotnet user-secrets init
dotnet user-secrets set "AzureAd:ClientId" "YOUR_APP_ID"
dotnet user-secrets set "AzureAd:ClientSecret" "YOUR_APP_SECRET"
Run the sample:
dotnet runSign in with your personal account (MSA) or your work or school account, and grant the requested permissions.
Choose a snippets category in the navigation bar, such as Users, Files, or Mail.
NOTE: If you logged in with a personal account, snippets that aren't supported for Microsoft accounts are removed from the navigation bar.
This sample creates, updates, and deletes entities and data (such as users or files). Depending on how you use it, you might edit or delete actual entities and data and leave data artifacts.
To use the sample without modifying your actual account data, be sure to perform update and delete operations only on entities that are created by the sample.
We'd love to get your feedback about this sample. You can send us your questions and suggestions in the Issues section of this repository.
Your feedback is important to us. Connect with us on Stack Overflow. Tag your questions with [MicrosoftGraph].
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Copyright (c) 2020 Microsoft. All rights reserved.
C#
70.1%
HTML
29.0%