Skip to content

Commit db49225

Browse files
author
Kalyan Krishna
committed
Attended to the PR methods
1 parent 0aeb74f commit db49225

19 files changed

+105
-69
lines changed

5-WebApp-AuthZ/5-1-Roles/AppCreationScripts/Configure.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Function ConfigureApplications
199199

200200
# create the service principal of the newly created application
201201
$currentAppId = $webAppAadApplication.AppId
202-
$webAppServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp} -AppRoleAssignmentRequired $true
202+
$webAppServicePrincipal = New-AzureADServicePrincipal -AppId $currentAppId -Tags {WindowsAzureActiveDirectoryIntegratedApp}
203203

204204
# add the user running the script as an app owner if needed
205205
$owner = Get-AzureADApplicationOwner -ObjectId $webAppAadApplication.ObjectId

5-WebApp-AuthZ/5-1-Roles/Infrastructure/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace WebApp_OpenIDConnect_DotNet.Infrastructure
33
public static class Constants
44
{
55
public const string ScopeUserRead = "User.Read";
6+
public const string ScopeUserReadAll = "User.ReadBasic.All";
67
public const string BearerAuthorizationScheme = "Bearer";
78
}
89
}

5-WebApp-AuthZ/5-1-Roles/README-incremental-instructions.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endpoint: Microsoft identity platform
1414

1515
### Overview
1616

17-
This sample shows how a .NET Core 2.2 MVC Web app that uses [OpenID Connect](https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-openid-connect-code) to sign in users and use Azure AD Application Roles (app roles) for authorization. App roles, along with Security groups are popular means to implement authorization.
17+
This sample shows how a .NET Core 2.2 MVC Web app that uses [OpenID Connect](https://docs.microsoft.com/azure/active-directory/develop/v1-protocols-openid-connect-code) to sign in users and use Azure AD Application Roles (app roles) for authorization. App roles, along with Security groups are popular means to implement authorization.
1818

1919
This application implements RBAC using Azure AD's Application Roles & Role Claims feature. Another approach is to use Azure AD Groups and Group Claims, as shown in [WebApp-GroupClaims](../../5-WebApp-AuthZ/5-2-Groups/README-incremental-instructions.md). Azure AD Groups and Application Roles are by no means mutually exclusive; they can be used in tandem to provide even finer grained access control.
2020

@@ -28,7 +28,7 @@ For more information about how the protocols work in this scenario and other sce
2828

2929
## Scenario
3030

31-
This sample first leverages the ASP.NET Core OpenID Connect middleware to sign in the user. On the home page it displays the various `claims` that the user's [ID Token](https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens) contained. The ID token is used by the asp.net security middleware to build the [ClaimsPrincipal](https://docs.microsoft.com/en-us/dotnet/api/system.security.claims.claimsprincipal), accessible via **HttpContext.User** in the code.
31+
This sample first leverages the ASP.NET Core OpenID Connect middleware to sign in the user. On the home page it displays the various `claims` that the user's [ID Token](https://docs.microsoft.com/azure/active-directory/develop/id-tokens) contained. The ID token is used by the asp.net security middleware to build the [ClaimsPrincipal](https://docs.microsoft.com/dotnet/api/system.security.claims.claimsprincipal), accessible via **HttpContext.User** in the code.
3232

3333
This web application allows users to list all users in their tenant or a list of all the roles and groups the signed in user is assigned to depending on the app role they have been assigned to. The idea is to provide an example of how, within an application, access to certain functionality is restricted to subsets of users depending on which role they belong to.
3434

@@ -39,7 +39,7 @@ This sample application defines the following two *Application Roles*:
3939
- `DirectoryViewers`: Have the ability to view any directory user's roles and security group assignments.
4040
- `UserReaders`: Have the ability to view a list of users in the directory.
4141

42-
These application roles are defined in the [Azure portal](https://portal.azure.com) in the application's registration manifest. When a user signs into the application, Azure AD emits a `roles` claim for each role that the user has been granted individually to the user in the from of role membership. Assignment of users and groups to roles can be done through the portal's UI, or programmatically using the [Microsoft Graph](https://graph.microsoft.com) and [Azure AD PowerShell](https://docs.microsoft.com/en-us/powershell/module/azuread/?view=azureadps-2.0). In this sample, application role management is done through the Azure portal or using PowerShell.
42+
These application roles are defined in the [Azure portal](https://portal.azure.com) in the application's registration manifest. When a user signs into the application, Azure AD emits a `roles` claim for each role that the user has been granted individually to the user in the from of role membership. Assignment of users and groups to roles can be done through the portal's UI, or programmatically using the [Microsoft Graph](https://graph.microsoft.com) and [Azure AD PowerShell](https://docs.microsoft.com/powershell/module/azuread/?view=azureadps-2.0). In this sample, application role management is done through the Azure portal or using PowerShell.
4343

4444
NOTE: Role claims will not be present for guest users in a tenant if the `/common` endpoint is used as the authority.
4545

@@ -62,7 +62,7 @@ To run this sample, you'll need:
6262
- A Windows machine (necessary if you want to run the app on Windows)
6363
- An OS X machine (necessary if you want to run the app on Mac)
6464
- A Linux machine (necessary if you want to run the app on Linux)
65-
- An Azure Active Directory (Azure AD) tenant. For more information on how to get an Azure AD tenant, see [How to get an Azure AD tenant](https://azure.microsoft.com/en-us/documentation/articles/active-directory-howto-tenant/)
65+
- An Azure Active Directory (Azure AD) tenant. For more information on how to get an Azure AD tenant, see [How to get an Azure AD tenant](https://azure.microsoft.com/documentation/articles/active-directory-howto-tenant/)
6666
- A user account in your Azure AD tenant. This sample will not work with a Microsoft account (formerly Windows Live account). Therefore, if you signed in to the [Azure portal](https://portal.azure.com) with a Microsoft account and have never created a user account in your directory before, you need to do that now.
6767

6868
### Step 1: Clone or download this repository
@@ -85,7 +85,7 @@ Navigate to the `"5-WebApp-AuthZ"` folder
8585

8686
### Step 2: Configure your application to receive the **roles** claims
8787

88-
1. To receive the `roles` claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this app.
88+
> Note: To receive the `roles` claim with the name of the app roles this user is assigned to, make sure that the user accounts you plan to sign-in to this app is assigned to the app roles of this app. The guide, [Assign a user or group to an enterprise app in Azure Active Directory](https://docs.microsoft.com/azure/active-directory/manage-apps/assign-user-or-group-access-portal#assign-a-user-to-an-app---portal) provides step by step instructions.
8989
9090
#### Step 3: Define your Application Roles
9191

@@ -128,7 +128,7 @@ The content of `appRoles` should be the following (the `id` should be a unique G
128128
}
129129
```
130130

131-
1. Follow the steps in the document [Assign users and groups to an application in Azure Active Directory](https://docs.microsoft.com/en-us/azure/active-directory/manage-apps/methods-for-assigning-users-and-groups#assign-users) to assign users to these roles.
131+
1. Follow the steps in the document [Assign users and groups to an application in Azure Active Directory](https://docs.microsoft.com/azure/active-directory/manage-apps/methods-for-assigning-users-and-groups#assign-users) to assign users to these roles.
132132

133133
- You can also use PowerShell scripts that **automatically** creates these two roles for your app. They additionally create two users in your tenant and assign them to these two roles. If you want to use this automation:
134134

@@ -156,19 +156,18 @@ The content of `appRoles` should be the following (the `id` should be a unique G
156156

157157
1. Clean the solution, rebuild the solution, and run it.
158158

159-
1. Open your web browser and make a request to the app. The app immediately attempts to authenticate you via the Microsoft identity platform endpoint. Sign in with a work or school account.
159+
1. Open your web browser and make a request to the app. The app immediately attempts to authenticate you via the Microsoft identity platform endpoint. Sign in using a user account of that tenant.
160160

161-
1. You will be prompted to consent during the sign-in process.
162161

163162
![First time Consent](ReadmeFiles/Sign-in-Consent.png)
164163

165-
1. On the home page, the app lists the various claims it obtained from your [ID token](https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens). You'd notice a claim named `roles`. There will be one `roles` claim for each app role the signed-in use is assigned to.
164+
1. On the home page, the app lists the various claims it obtained from your [ID token](https://docs.microsoft.com/azure/active-directory/develop/id-tokens). You'd notice a claim named `roles`. There will be one `roles` claim for each app role the signed-in use is assigned to.
166165

167166
1. There also are two links provided on the home page under the **Try one of the following Azure App Role driven operations** heading. These links will result in an access denied error if the signed-in user is not present in the expected role. Sign-out and sign-in with a user account with the correct role assignment to view the contents of these pages.
168167

169-
> Note: You need to be a tenant admin to view the page that lists all the groups and roles the signed-in user is assigned to. It requires the **Directory.Read.All** permission to work. If you run into the **AADSTS65001: The user or administrator has not consented to use the application** error, provide [admin consent](https://docs.microsoft.com/en-us/azure/active-directory/manage-apps/configure-user-consent#grant-admin-consent-when-registering-an-app-in-the-azure-portal) to your app in the portal. Sign-out and sign-in again to make the page work as expected.
168+
> Note: You need to be a tenant admin to view the page that lists all the groups and roles the signed-in user is assigned to. It requires the **Directory.Read.All** permission to work. If you run into the **AADSTS65001: The user or administrator has not consented to use the application** error, provide [admin consent](https://docs.microsoft.com/azure/active-directory/manage-apps/configure-user-consent#grant-admin-consent-when-registering-an-app-in-the-azure-portal) to your app in the portal. Sign-out and sign-in again to make the page work as expected.
170169
171-
When you click on the page that fetches the signed-in user's roles and group assignments, the sample will attempt to obtain consent from you for the **Directory.Read.All** permission using [incremental consent](https://docs.microsoft.com/en-us/azure/active-directory/develop/azure-ad-endpoint-comparison#incremental-and-dynamic-consent).
170+
When you click on the page that fetches the signed-in user's roles and group assignments, the sample will attempt to obtain consent from you for the **Directory.Read.All** permission using [incremental consent](https://docs.microsoft.com/azure/active-directory/develop/azure-ad-endpoint-comparison#incremental-and-dynamic-consent).
172171

173172
> Did the sample not work for you as expected? Did you encounter issues trying this sample? Then please reach out to us using the [GitHub Issues](../../../../issues) page.
174173
@@ -190,7 +189,7 @@ public static IServiceCollection AddMicrosoftIdentityPlatformAuthentication(this
190189
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
191190

192191
// The following lines code instruct the asp.net core middleware to use the data in the "groups" claim in the Authorize attribute and User.IsInrole()
193-
// See https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-2.2 for more info.
192+
// See https://docs.microsoft.com/aspnet/core/security/authorization/roles?view=aspnetcore-2.2 for more info.
194193
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
195194
{
196195
// Use the groups claim for populating roles
@@ -202,7 +201,7 @@ public static IServiceCollection AddMicrosoftIdentityPlatformAuthentication(this
202201
// In code..(Controllers & elsewhere)
203202
[Authorize(Roles = DirectoryViewers")] // In controllers
204203
// or
205-
User.IsInRole("USerReaders"); // In methods
204+
User.IsInRole("UserReaders"); // In methods
206205
```
207206

208207
## About the code
@@ -300,12 +299,12 @@ To understand more about app registration, see:
300299
301300
To understand more about groups roles and the various claims in tokens, see:
302301

303-
- [Azure Active Directory app manifest](https://docs.microsoft.com/en-us/azure/active-directory/develop/reference-app-manifest)
304-
- [ID tokens](https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens)
305-
- [Azure Active Directory access tokens](https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens)
306-
- [Microsoft Graph permissions reference](https://docs.microsoft.com/en-us/graph/permissions-reference)
307-
- [user: getMemberObjects function](https://docs.microsoft.com/en-us/graph/api/user-getmemberobjects?view=graph-rest-1.0)
308-
- [Application roles](https://docs.microsoft.com/en-us/azure/architecture/multitenant-identity/app-roles)
302+
- [Azure Active Directory app manifest](https://docs.microsoft.com/azure/active-directory/develop/reference-app-manifest)
303+
- [ID tokens](https://docs.microsoft.com/azure/active-directory/develop/id-tokens)
304+
- [Azure Active Directory access tokens](https://docs.microsoft.com/azure/active-directory/develop/access-tokens)
305+
- [Microsoft Graph permissions reference](https://docs.microsoft.com/graph/permissions-reference)
306+
- [user: getMemberObjects function](https://docs.microsoft.com/graph/api/user-getmemberobjects?view=graph-rest-1.0)
307+
- [Application roles](https://docs.microsoft.com/azure/architecture/multitenant-identity/app-roles)
309308
- [Token validation](https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/wiki/ValidatingTokens)
310309
311310
## Contributing

0 commit comments

Comments
 (0)