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: README.md
+72-31Lines changed: 72 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,56 +32,97 @@ You can clone this sample from your shell or command line:
32
32
33
33
### Step 2: Register your Web API - *TodoListService* in the *Application registration portal*
34
34
35
-
1. Sign in to the [Application registration portal](https://apps.dev.microsoft.com/portal/register-app) either using a personal Microsoft account (live.com or hotmail.com) or work or school account.
36
-
1. Give a name to your Application, such as `AppModelv2-NativeClient-DotNet-TodoListService`. Make sure that the *Guided Setup* option is **Unchecked** then press **Create**. The portal will assign your app a globally unique *Application ID* that you'll use later in your code.
37
-
1. Click **Add Platform**, and select **Web API**
38
-
1. Click **Save**
39
-
40
-
> Note: When you add a *Web API* the Application registration portal, it adds a pre-defined App Id URI and Scope, using the format *api://{Application Id}/{Scope Name}* named **access_as_user** (you can review it by clicking 'Edit' button). This sample code uses this default scope.
41
-
42
-
### Step 3: Configure your *TodoListService* and *TodoListClient* projects to match the Web API you just registered
35
+
#### Choose the Azure AD tenant where you want to create your applications
36
+
37
+
If you want to register your apps manually, as a first step you'll need to:
38
+
39
+
1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account or a personal Microsoft account.
40
+
1. If your account is present in more than one Azure AD tenant, select your profile at the top right corner in the menu on top of the page, and then **switch directory**.
41
+
Change your portal session to the desired Azure AD tenant.
42
+
43
+
#### Register the service app (TodoListService)
44
+
45
+
1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
46
+
1. Select **New registration**.
47
+
1. When the **Register an application page** appears, enter your application's registration information:
48
+
- In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `AppModelv2-NativeClient-DotNet-TodoListService`.
49
+
- Change **Supported account types** to **Accounts in any organizational directory**.
50
+
- Select **Register** to create the application.
51
+
52
+
1. On the app **Overview** page, find the **Application (client) ID** value and record it for later. You'll need it to configure the Visual Studio configuration file for this project (`ClientId` in `TodoListService\Web.config`).
53
+
1. Select the **Expose an API** section, and:
54
+
- Select **Add a scope**
55
+
- accept the proposed Application ID URI (api://{clientId}) by selecting **Save and Continue**
56
+
- Enter the following parameters:
57
+
- for **Scope name** use `access_as_user`
58
+
- Ensure the **Admins and users** option is selected for **Who can consent**
59
+
- in **Admin consent display name** type `Access TodoListService as a user`
60
+
- in **Admin consent description** type `Accesses the TodoListService Web API as a user`
61
+
- in **User consent display name** type `Access TodoListService as a user`
62
+
- in **User consent description** type `Accesses the TodoListService Web API as a user`
63
+
- Keep **State** as **Enabled**
64
+
- Select **Add scope**
65
+
66
+
#### Configure your *TodoListService* and *TodoListClient* projects to match the Web API you just registered
43
67
44
68
1. Open the solution in Visual Studio and then open the **Web.config** file under the root of **TodoListService** project.
45
-
1. Replace the value of `ida:ClientId` parameter with the **Application Id** from the application you just registered in the Application Registration Portal.
69
+
1. Replace the value of `ida:ClientId` parameter with the **Client ID (Application Id)** from the application you just registered in the Application Registration Portal.
70
+
71
+
#### Add the new scope to the *TodoListClient*`s app.config
46
72
47
-
#### Step 3.1: Add the new scope to the *TodoListClient*`s app.config
73
+
1. Open the **app.config** file located in **TodoListClient** project's root folder and then paste **Application Id** from the application you just registered for your *TodoListService* under `TodoListServiceScope` parameter, replacing the string `{Enter the Application Id of your TodoListService from the app registration portal}`.
48
74
49
-
1. Open the **app.config** file located in **TodoListClient** project's root folder and then paste **Application Id** from the application you just registered for your *TodoListService* under `TodoListServiceScope` parameter, replacing the string `{Enter the Application Id of your TodoListService from the app registration portal}`.
>(where {TodoListService-Application-Id} is the Guid representing the Application Id for your TodoListService).
50
80
51
-
> Note: Make sure it uses has the format `api://{TodoListService-Application-Id}/access_as_user` (where {TodoListService-Application-Id} is the Guid representing the Application Id for your TodoListService).
81
+
### Step 3: Register the client app (TodoListClient)
52
82
53
-
### Step 4: Register the *TodoListClient* application in the *Application registration portal*
83
+
In this step, you configure your *TodoListClient*project by registering a new application in the Application registration portal. In the cases where the client and server are considered *the same application* you may also just reuse the same application registered in the 'Step 2.'. Using the same application is actually needed if you want users to sign-in with Microsoft personal accounts
54
84
55
-
In this step, you configure your *TodoListClient*project by registering a new application in the Application registration portal. In the cases where the client and server are considered *the same application* you may also just reuse the same application registered in the 'Step 2.'.
85
+
#### Register the *TodoListClient* application in the *Application registration portal*
56
86
57
-
1. Go back to [Application registration portal](https://apps.dev.microsoft.com/portal/register-app) to register a new application
58
-
1. Give a name to your Application, such as `NativeClient-DotNet-TodoListClient`, make sure that the *Guided Setup* option is **Unchecked** then press **Create**.
59
-
1. Click **Add Platform**, and select **Native**.
60
-
1. Click **Save**
87
+
1. Navigate to the Microsoft identity platform for developers [App registrations](https://go.microsoft.com/fwlink/?linkid=2083908) page.
88
+
1. Select **New registration**.
89
+
1. When the **Register an application page** appears, enter your application's registration information:
90
+
- In the **Name** section, enter a meaningful application name that will be displayed to users of the app, for example `NativeClient-DotNet-TodoListClient`.
91
+
- Change **Supported account types** to **Accounts in any organizational directory**.
92
+
- Select **Register** to create the application.
93
+
1. From the app's Overview page, select the **Authentication** section.
94
+
- In the **Redirect URLs** | **Suggested Redirect URLs for public clients (mobile, desktop)** section, check **urn:ietf:wg:oauth:2.0:oob**
95
+
- Select **Save**.
96
+
1. Select the **API permissions** section
97
+
- Click the **Add a permission** button and then,
98
+
- Select the **My APIs** tab.
99
+
- In the list of APIs, select the `AppModelv2-NativeClient-DotNet-TodoListService API`, or the name you entered for the Web API.
100
+
- Check the **access_as_user** permission if it's not already checked. Use the search box if necessary.
101
+
- Select the **Add permissions** button
61
102
62
-
###Step 5: Configure your *TodoListClient* project
103
+
####Configure your *TodoListClient* project
63
104
64
-
1. In the *Application registration portal*, copy the value of the **Application Id**
105
+
1. In the *Application registration portal*, in the **Overview** page copy the value of the **Application (client) Id**
65
106
1. Open the **app.config** file located in the **TodoListClient** project's root folder and then paste the value in the `ida:ClientId` parameter value
66
107
67
-
### Step 6: Run your project
108
+
### Step 4: Run your project
68
109
69
110
1. Press `<F5>` to run your project. Your *TodoListClient* should open.
70
-
1. Select **Sign in** in the top right and sign in with the same user you have used to register your aplication, or a user in the same directory.
111
+
1. Select **Sign in** in the top right and sign in with the same user you have used to register your application, or a user in the same directory.
71
112
1. At this point, if you are signing in for the first time, you may be prompted to consent to *TodoListService* Web Api.
72
113
1. The sign-in also request the access token to the *access_as_user* scope to access *TodoListService* Web Api and manipulate the *To-Do* list.
73
114
74
-
### Step 7: Pre-authorize your client application
115
+
### Step 5: Pre-authorize your client application
75
116
76
-
One of the ways to allow users from other directories to acces your Web API is by *pre-authorizing* the client applications to access your Web API by adding the Application Ids from client applications in the list of *pre-authorized* applications for your Web API. By adding a pre-authorized client, you will not require user to consent to use your Web API. Follow the steps below to pre-authorize your Web Application::
117
+
One of the ways to allow users from other directories to access your Web API is by *pre-authorizing* the client applications to access your Web API by adding the Application Ids from client applications in the list of *pre-authorized* applications for your Web API. By adding a pre-authorized client, you will not require user to consent to use your Web API. Follow the steps below to pre-authorize your Web Application::
77
118
78
119
1. Go back to the *Application registration portal* and open the properties of your **TodoListService**.
79
-
1. In the **Web API platform**, click on **Add application** under the *Pre-authorized applications* section.
80
-
1. In the *Application ID* field, paste the application ID of the `TodoListClient` application.
81
-
1. In the *Scope* field, click on the **Select** combo box and select the scope for this Web API `api://<Application ID>/access_as_user`.
82
-
1. Press the **Save** button at the bottom of the page.
120
+
1. In the **Expose an API** section, click on **Add a client application** under the *Authorized client applications* section.
121
+
1. In the *Client ID* field, paste the application ID of the `TodoListClient` application.
122
+
1. In the *Authorized scopes* section, select the scope for this Web API `api://<Application ID>/access_as_user`.
123
+
1. Press the **Add application** button at the bottom of the page.
83
124
84
-
### Step 8: Run your project
125
+
### Step 6: Run your project
85
126
86
127
1. Press `<F5>` to run your project. Your *TodoListClient* should open.
87
128
1. Select **Sign in** in the top right (or Clear Cache/Sign-in) and then sign-in either using a personal Microsoft account (live.com or hotmail.com) or work or school account.
@@ -96,8 +137,8 @@ To restrict who can sign in to your application, use one of the options:
96
137
97
138
You can restrict sign-in access for your application to only user accounts that are in a single Azure AD tenant - including *guest accounts* of that tenant. This scenario is a common for *line-of-business applications*:
98
139
99
-
1.In the **web.config** file of your **TodoListService**, change the value for the `Tenant` parameter from `Common` to the tenant name of the organization, such as `contoso.onmicrosoft.com` or the *Tenant Id*.
100
-
2.Open **App_Start\Startup.Auth**file and set the `ValidateIssuer` argument to `true`.
140
+
1.Open the **App_Start\Startup.Auth** file, and change the value of the metadata endpoint that's passed into the `OpenIdConnectSecurityTokenProvider` to `"https://login.microsoftonline.com/{Tenant ID}/v2.0/.well-known/openid-configuration"` (you can also use the Tenant Name, such as `contoso.onmicrosoft.com`).
141
+
2.In the same file, set the `ValidIssuer` property on the `TokenValidationParameters` to `"https://sts.windows.net/{Tenant Id}/"` and the `ValidateIssuer` argument to `true`.
101
142
102
143
#### Option 2: Use a custom method to validate issuers
0 commit comments