Skip to content

Commit 2f8e0f4

Browse files
committed
minor working updates
1 parent 9fa8f01 commit 2f8e0f4

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

4-WebApp-your-API/4-1-MyOrg/AppCreationScripts/Configure.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ Function CreateOptionalClaim([string] $name)
170170

171171
Function ConfigureApplications
172172
{
173+
$isOpenSSl = 'N' #temporary disable open certificate creation
174+
173175
<#.Description
174176
This function creates the Azure AD applications for the sample in the provided Azure AD tenant and updates the
175177
configuration files in the client and service project of the visual studio solution (App.Config and Web.Config)

4-WebApp-your-API/4-1-MyOrg/AppCreationScripts/sample.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"Service": "ASP.NET Core Web API",
88
"RepositoryUrl": "active-directory-aspnetcore-webapp-openidconnect-v2",
99
"Endpoint": "AAD v2.0",
10-
"Description": "This sample demonstrates a ASP.NET Core Web App signing-in a user and calling a ASP.NET Core Web API that is secured with Azure AD.",
10+
"Description": "This sample demonstrates an ASP.NET Core Web App signing-in a user and calling an ASP.NET Core Web API that is secured with Azure AD.",
1111
"Languages": [ "csharp" ],
1212
"Products": [ "aspnet-core", "azure-active-directory" ]
1313
},

4-WebApp-your-API/4-1-MyOrg/README-use-certificate.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This sample was configured to use a client secret, but have an option to use a c
2828
]
2929
```
3030

31-
1. While inside '4-1-MyOrg' folder, open a Powershell terminal
31+
1. While inside the sample folder, open a Powershell terminal
3232

3333
1. Set next execution policy
3434

@@ -76,7 +76,7 @@ AppCreationScripts-withCert/Configure.ps1
7676
]
7777
```
7878

79-
1. While inside '4-1-MyOrg' folder, open a Powershell terminal
79+
1. While inside the sample folder, open a Powershell terminal
8080

8181
1. Set next execution policy
8282

4-WebApp-your-API/4-1-MyOrg/README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ products:
99
- aspnet-core
1010
- azure-active-directory
1111
urlFragment: active-directory-aspnetcore-webapp-openidconnect-v2
12-
description: This sample demonstrates an ASP.NET Core client Web App calling an ASP.NET Core Web API that is secured using Azure AD.
12+
description: This sample demonstrates an ASP.NET Core Web App signing-in a user and calling an ASP.NET Core Web API that is secured with Azure AD.
1313
---
1414

1515
# How to secure an ASP.NET Core Web API with the Microsoft identity platform
@@ -38,8 +38,8 @@ This sample demonstrates a ASP.NET Core Web App calling a ASP.NET Core Web API t
3838

3939
This sample demonstrates an ASP.NET Core client Web App calling an ASP.NET Core Web API that is secured using Azure AD.
4040

41-
1. The client ASP.NET Core Web App uses the [Microsoft.Identity.Web](https://aka.ms/microsoft-identity-web) to sign-in a user and obtain a JWT [Access Token](https://aka.ms/access-tokens) from **Azure AD** for the web API.
42-
2. The service app uses the the [Microsoft.Identity.Web](https://aka.ms/microsoft-identity-web) to protect the Web api, and validate Access tokens.
41+
1. The client ASP.NET Core Web App uses the [Microsoft.Identity.Web](https://aka.ms/microsoft-identity-web) to sign-in a user and obtain a JWT [Id Token](https://docs.microsoft.com/azure/active-directory/develop/id-tokens) from **Azure AD**.
42+
2. The service again uses the the [Microsoft.Identity.Web](https://aka.ms/microsoft-identity-web) to protect the Web api, and validate tokens.
4343

4444
![Scenario Image](./ReadmeFiles/topology.png)
4545

@@ -193,13 +193,13 @@ Open the project in your IDE (like Visual Studio or Visual Studio Code) to confi
193193
1. Select one of the available key durations (**6 months**, **12 months** or **Custom**) as per your security posture.
194194
1. The generated key value will be displayed when you select the **Add** button. Copy and save the generated value for use in later steps.
195195
1. You'll need this key later in your code's configuration files. This key value will not be displayed again, and is not retrievable by any other means, so make sure to note it from the Azure portal before navigating to any other screen or blade.
196-
> :bulb: For enhanced security, instead of using client secrets, consider [using certificates](./README-use-certificate.md) and [Azure KeyVault](https://azure.microsoft.com/services/key-vault/#product-overview).
197-
1. Since this app signs-in users, we will now proceed to select **delegated permissions**, which is is required by apps signing-in users.
196+
> :bulb: For enhanced security, instead of using client secrets, consider [using certificates](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/certificate-credentials.md) and [Azure KeyVault](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/docs/key-vault-managed-identity.md).1. Since this app signs-in users, we will now proceed to select **delegated permissions**, which is is required by apps signing-in users.
198197
1. In the app's registration screen, select the **API permissions** blade in the left to open the page where we add access to the APIs that your application needs:
199198
1. Select the **Add a permission** button and then,
200199
1. Ensure that the **My APIs** tab is selected.
201200
1. In the list of APIs, select the API `TodoListService-aspnetcore-webapi`.
202-
1. In the **Delegated permissions** section, select the **ToDoList.Read**, **ToDoList.ReadWrite** in the list. Use the search box if necessary.
201+
* Since this app signs-in users, we will now proceed to select **delegated permissions**, which is is requested by apps when signing-in users.
202+
1. In the **Delegated permissions** section, select the **ToDoList.Read**, **ToDoList.ReadWrite** in the list. Use the search box if necessary.
203203
1. Select the **Add permissions** button at the bottom.
204204
205205
##### Configure the client app (TodoListClient-aspnetcore-webapi) to use your app registration
@@ -306,19 +306,19 @@ To provide a recommendation, visit the following [User Voice page](https://feedb
306306
AcceptedScope = new string[] { "ToDoList.Read", "ToDoList.ReadWrite" },
307307
AcceptedAppPermission = new string[] { "ToDoList.Read.All", "ToDoList.ReadWrite.All" }
308308
)]
309-
public IEnumerable<Todo> Get()
310-
{
309+
public IEnumerable<Todo> Get()
310+
{
311311
if (!IsAppOnlyToken())
312-
{
313-
// this is a request for all ToDo list items of a certain user.
314-
return TodoStore.Values.Where(x => x.Owner == _currentLoggedUser);
315-
}
316-
else
317-
{
318-
// Its an app calling with app permissions, so return all items across all users
319-
return TodoStore.Values;
320-
}
321-
}
312+
{
313+
// this is a request for all ToDo list items of a certain user.
314+
return TodoStore.Values.Where(x => x.Owner == _currentLoggedUser);
315+
}
316+
else
317+
{
318+
// Its an app calling with app permissions, so return all items across all users
319+
return TodoStore.Values;
320+
}
321+
}
322322
```
323323

324324
The code above demonstrates that to be able to reach a GET REST operation, the access token should contain AT LEAST ONE of the scopes (delegated permissions) listed inside parameter of [RequiredScopeOrAppPermission](https://github.com/AzureAD/microsoft-identity-web/wiki/web-apis#checking-for-scopes-or-app-permissions=) attribute
@@ -333,8 +333,8 @@ To provide a recommendation, visit the following [User Voice page](https://feedb
333333
[RequiredScopeOrAppPermission(
334334
AcceptedScope = new string[] { "ToDoList.ReadWrite" },
335335
AcceptedAppPermission = new string[] { "ToDoList.ReadWrite.All" })]
336-
public void Delete(int id)
337-
{
336+
public void Delete(int id)
337+
{
338338
if (!IsAppOnlyToken())
339339
{
340340
// only delete if the ToDo list item belonged to this user
@@ -347,7 +347,7 @@ To provide a recommendation, visit the following [User Voice page](https://feedb
347347
{
348348
TodoStore.Remove(id);
349349
}
350-
}
350+
}
351351
```
352352

353353
The above code demonstrates that to be able to execute the DELETE REST operation, the access token MUST contain the `ToDoList.ReadWrite` scope. Note that the called is not allowed to access this operation with just `ToDoList.Read` scope only.
@@ -379,6 +379,7 @@ services.AddMicrosoftIdentityWebAppAuthentication(Configuration)
379379

380380
</details>
381381

382+
382383
## How the code was created
383384

384385
<details>

0 commit comments

Comments
 (0)