You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/proxy-provider-asp-net-core/README.md
+88-25Lines changed: 88 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,51 +32,114 @@ This custom implementation simply proxies every method (**GET**, **POST**, **DEL
32
32
33
33
### Prerequisites
34
34
35
-
To run the completed project in this folder, you need the following:
35
+
To use the Microsoft Graph Connect Sample for ASP.NET Core 3.1, you need the following:
36
36
37
-
-[Visual Studio](https://visualstudio.microsoft.com/vs/) installed on your development machine. If you do not have Visual Studio, visit the previous link for download options. (**Note:** This tutorial was written with Visual Studio 2019 version 16.5.3. The steps in this guide may work with other versions, but that has not been tested.)
38
-
- A Microsoft work or school account.
37
+
- Visual Studio 2019 [with .NET Core 3.1 SDK](https://www.microsoft.com/net/download/core) installed on your development computer.
38
+
- Either a [personal Microsoft account](https://signup.live.com) or a [work or school account](https://dev.office.com/devprogram). (You don't need to be an administrator of the tenant.)
39
+
- The application ID and key from the application that you [register on the App Registration Portal](#register-the-app).
39
40
40
-
If you don't have a Microsoft work or school account, you can [sign up for the Office 365 Developer Program](https://developer.microsoft.com/office/dev-program) to get a free Office 365 development subscription.
41
+
### Register the app
41
42
42
-
### Register a web application with the Azure Active Directory admin center
43
+
1. Navigate to the [Azure AD Portal](https://portal.azure.com). Login using a **personal account** (aka: Microsoft Account) or **Work or School Account** with permissions to create app registrations.
43
44
44
-
1. Determine your ASP.NET applications's SSL URL. In this project, it is set to `https://localhost:44334`.
45
+
> **Note:** If you do not have permissions to create app registrations contact your Azure AD domain administrators.
45
46
46
-
1. Open a browser and navigate to the [Azure Active Directory admin center](https://aad.portal.azure.com). Login using a **personal account** (aka: Microsoft Account) or **Work or School Account**.
47
+
2. Click **Azure Active Directory** from the left-hand navigation menu.
47
48
48
-
1. Select**Azure Active Directory**in the left-hand navigation, then select **App registrations** under **Manage**.
49
+
3. Click**App registrations**from the current blade navigation pane.
49
50
51
+
4. Click **New registration** from the current blade content.
50
52
51
-
1. Select **New registration**. On the **Register an application** page, set the values as follows.
53
+
5.On the **Register an application** page, specify the following values:
52
54
53
-
- Set **Name** to `ASP.NET Graph Tutorial` (or any other value).
54
-
- Set **Supported account types** to **Accounts in any organizational directory and personal Microsoft accounts**.
55
-
- Under **Redirect URI**, set the first drop-down to `Web` and set the value to the ASP.NET app URL you copied in step 1.
55
+
-**Name** = [Desired app name]
56
+
-**Supported account types** = [Choose the value that applies to your needs]
57
+
-**Redirect URI**
58
+
- Type (dropdown) = Web
59
+
- Value = `https://localhost:44334/signin-oidc`
56
60
61
+
> **Note:** Ensure that the Redirect URI value is unique within your domain. This value can be changed at a later time and does not need to point to a hosted URI. If the example URI above is already used please choose a unique value.
57
62
58
-
1. Choose **Register**. On the **ASP.NET Graph Tutorial** page, copy the value of the **Application (client) ID** and save it, you will need it in the next step.
63
+
1. Under **Advanced settings**, set the value of the **Logout URL** to `https://localhost:44334/Account/SignOut`
64
+
2. Copy the **Redirect URI** as you will need it later.
59
65
66
+
6. Once the app is created, copy the **Application (client) ID** and **Directory (tenant) ID** from the overview page and store it temporarily as you will need both later.
60
67
61
-
1. Select**Authentication** under **Manage**. Locate the **Implicit grant** section and enable **ID tokens**. Choose **Save**.
68
+
7. Click**Certificates & secrets** from the current blade navigation pane.
62
69
70
+
1. Click **New client secret**.
71
+
2. On the **Add a client secret** dialog, specify the following values:
63
72
64
-
1. 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 choose **Add**.
73
+
-**Description** = MyAppSecret1
74
+
-**Expires** = In 1 year
65
75
76
+
3. Click **Add**.
66
77
67
-
1. Copy the client secret value before you leave this page. You will need it in the next step.
78
+
4. After the screen has updated with the newly created client secret copy the **VALUE** of the client secret and store it temporarily as you will need it later.
68
79
69
-
> [!IMPORTANT]
70
-
> This client secret is never shown again, so make sure you copy it now.
80
+
> **Important:** This secret string is never shown again, so make sure you copy it now.
81
+
> In production apps you should always use certificates as your application secrets, but for this sample we will use a simple shared secret password.
71
82
83
+
8. Click **Authentication** from the current blade navigation pane.
84
+
1. Select 'ID tokens'
85
+
9. Click **API permissions** from the current blade navigation pane.
72
86
73
-
### Configure the sample
87
+
1. Click **Add a permission** from the current blade content.
88
+
2. On the **Request API permissions** panel select **Microsoft Graph**.
74
89
75
-
1. Edit the `appsettings.json` file and make the following changes.
76
-
1. Replace `YOUR_APP_ID_HERE` with the **Application Id** you got from the App Registration Portal.
77
-
1. Replace `YOUR_APP_PASSWORD_HERE` with the **Application Secret** you got from the App Registration Portal.
78
-
1. In Solution Explorer, right-click the **mgt-netcore** solution and choose **Restore NuGet Packages**.
90
+
3. Select **Delegated permissions**.
91
+
4. In the "Select permissions" search box type "User".
92
+
5. Select **openid**, **email**, **profile**, **offline_access**, **User.Read**, **User.ReadBasic.All** and **Mail.Send**.
79
93
80
-
### Run the sample
94
+
6. Click **Add permissions** at the bottom of flyout.
81
95
82
-
In Visual Studio, press **F5** or choose **Debug > Start Debugging**.
96
+
> **Note:** Microsoft recommends that you explicitly list all delegated permissions when registering your app. While the incremental and dynamic consent capabilities of the v2 endpoint make this step optional, failing to do so can negatively impact admin consent.
97
+
98
+
### Configure and run the sample
99
+
100
+
1. Download or clone the Microsoft Graph Connect Sample for ASP.NET Core.
101
+
102
+
2. Open the **MicrosoftGraphAspNetCoreConnectSample.sln** sample file in Visual Studio 2019.
103
+
104
+
3. In Solution Explorer, open the **appsettings.json** file in the root directory of the project.
105
+
106
+
a. For the **AppId** key, replace `ENTER_YOUR_APP_ID` with the application ID of your registered application.
107
+
108
+
b. For the **AppSecret** key, replace `ENTER_YOUR_SECRET` with the password of your registered application. Note that in production apps you should always use certificates as your application secrets, but for this sample we will use a simple shared secret password.
109
+
110
+
4. Press F5 to build and run the sample. This will restore NuGet package dependencies and open the app.
111
+
112
+
> If you see any errors while installing packages, make sure the local path where you placed the solution is not too long/deep. Moving the solution closer to the root of your drive resolves this issue.
113
+
114
+
5. Sign in with your personal (MSA) account or your work or school account and grant the requested permissions.
115
+
116
+
6. You should see your profile picture and your profile data in JSON on the start page.
117
+
118
+
7. Change the email address in the box to another valid account's email in the same tenant and choose the **Load data** button. When the operation completes, the profile of the choosen user is displayed on the page.
119
+
120
+
8. Optionally edit the recipient list, and then choose the **Send email** button. When the mail is sent, a Success message is displayed on the top of the page.
121
+
122
+
## Key components of the sample
123
+
124
+
The following files contain code that's related to connecting to Microsoft Graph, loading user data and sending emails.
125
+
126
+
-[`appsettings.json`](Proxy-Provider-Asp-Net-Core/appsettings.json) Contains values used for authentication and authorization.
127
+
-[`Startup.cs`](Proxy-Provider-Asp-Net-Core/Startup.cs) Configures the app and the services it uses, including authentication.
128
+
129
+
### Controllers
130
+
131
+
-[`AccountController.cs`](Proxy-Provider-Asp-Net-Core/Controllers/AccountController.cs) Handles sign in and sign out.
132
+
-[`HomeController.cs`](Proxy-Provider-Asp-Net-Core/Controllers/HomeController.cs) Handles the requests from the UI.
133
+
134
+
### Views
135
+
136
+
-[`Index.cshtml`](Proxy-Provider-Asp-Net-Core/Views/Home/Index.cshtml) Contains the sample's UI.
137
+
138
+
### Helpers
139
+
140
+
-[`GraphAuthProvider.cs`](Proxy-Provider-Asp-Net-Core/Helpers/GraphAuthProvider.cs) Gets an access token using MSAL's **AcquireTokenSilent** method.
141
+
-[`GraphSdkHelper.cs`](Proxy-Provider-Asp-Net-Core/Helpers/GraphSDKHelper.cs) Initiates the SDK client used to interact with Microsoft Graph.
142
+
-[`GraphService.cs`](Proxy-Provider-Asp-Net-Core/Helpers/GraphService.cs) Contains methods that use the **GraphServiceClient** to build and send calls to the Microsoft Graph service and to process the response.
143
+
- The **GetUserJson** action gets the user's profile by an email address and converts it to JSON.
144
+
- The **GetPictureBase64** action gets the user's profile picture and converts it to a base64 string.
145
+
- The **SendEmail** action sends an email on behalf of the current user.
0 commit comments