Skip to content

Commit 88e25e2

Browse files
author
Tiago Brenck
committed
Minor fixes
1 parent 0de72d3 commit 88e25e2

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

5-WebApp-AuthZ/5-2-Groups/Controllers/UserProfileController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace WebApp_OpenIDConnect_DotNet.Controllers
1111
{
12-
// [Authorize(Roles = "8873daa2-17af-4e72-973e-930c94ef7549")] // Using groups ids in the Authorize attribute
12+
// This is how groups ids/names are used in the Authorize attribute
13+
//[Authorize(Roles = "8873daa2-17af-4e72-973e-930c94ef7549")]
1314
public class UserProfileController : Controller
1415
{
1516
private readonly ITokenAcquisition tokenAcquisition;
@@ -24,7 +25,7 @@ public UserProfileController(ITokenAcquisition tokenAcquisition, IMSGraphService
2425
[AuthorizeForScopes(Scopes = new[] { Constants.ScopeUserRead, Constants.ScopeDirectoryReadAll })]
2526
public async Task<IActionResult> Index()
2627
{
27-
// Using group ids/names in the IsInRole method
28+
// This is how group ids/names are used in the IsInRole method
2829
// var isinrole = User.IsInRole("8873daa2-17af-4e72-973e-930c94ef7549");
2930

3031
string accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(new[] { Constants.ScopeUserRead, Constants.ScopeDirectoryReadAll });

5-WebApp-AuthZ/5-2-Groups/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ This project was created using the following command.
316316
> Note: Replace *`Enter_the_Application_Id_here`* with the *Application Id* from the application Id you just registered in the Application Registration Portal and *`<yourTenantId>`* with the *Directory (tenant) ID* where you created your application.
317317

318318
1. Open the generated project (.csproj) in Visual Studio, and save the solution.
319-
1. Add the `Microsoft.Identity.Web.csproj` project which is located at the root of this sample repo, to your solution (**Add Existing Project ...**). It's used to simplify signing-in and, in the next tutorial phases, to get a token
320-
1. Add a reference from your newly generated project to `Microsoft.Identity.Web` (right click on the **Dependencies** node under your new project, and choose **Add Reference ...**, and then in the projects tab find the `Microsoft.Identity.Web` project)
319+
1. Add the `Microsoft.Identity.Web` NuGet package. It's used to simplify signing-in and, in the next tutorial phases, to get a token.
321320
1. Open the **Startup.cs** file and:
322321

323322
- at the top of the file, add the following using directive:

5-WebApp-AuthZ/5-2-Groups/Startup.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,18 @@ public void ConfigureServices(IServiceCollection services)
3535
options.HandleSameSiteCookieCompatibility();
3636
});
3737

38-
// TODO: Tiago, please investigate
39-
//// Sign-in users with the Microsoft identity platform
40-
//services.AddSignIn(options =>
41-
// {
42-
// // Uncomment the following lines code instruct the asp.net core middleware to use the data in the "groups" claim in the [Authorize] attribute and for User.IsInrole()
43-
// // See https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles for more info.
44-
// // // Use the groups claim for populating roles
45-
// // options.TokenValidationParameters.RoleClaimType = "groups";
46-
// }, options =>
47-
// {
48-
// Configuration.Bind("AzureAd", options);
49-
// });
50-
38+
// Sign-in users with the Microsoft identity platform
5139
services.AddSignIn(Configuration);
5240

41+
// If you want to use group ids/names in the Authorize attribute then uncomment the following lines:
42+
//services.Configure<OpenIdConnectOptions>(options =>
43+
//{
44+
// // Uncomment the following lines code instruct the asp.net core middleware to use the data in the "groups" claim in the [Authorize] attribute and for User.IsInrole()
45+
// // See https://docs.microsoft.com/en-us/aspnet/core/security/authorization/roles for more info.
46+
// // Use the groups claim for populating roles
47+
// options.TokenValidationParameters.RoleClaimType = "groups";
48+
//});
49+
5350
services.AddWebAppCallsProtectedWebApi(Configuration, new string[] { "User.Read", "Directory.Read.All" })
5451
.AddInMemoryTokenCaches();
5552

5-WebApp-AuthZ/5-2-Groups/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
<span class="icon-bar"></span>
2727
<span class="icon-bar"></span>
2828
</button>
29-
<a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">@ViewData["Title"]</a>
29+
<a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">AuthZ-Groups</a>
3030
</div>
3131
<div class="navbar-collapse collapse">
3232
<ul class="nav navbar-nav">
3333
<li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
34+
<li><a asp-area="" asp-controller="UserProfile" asp-action="Index">Profile and Groups</a></li>
3435
</ul>
3536
<partial name="_LoginPartial" />
3637
</div>

0 commit comments

Comments
 (0)