File tree Expand file tree Collapse file tree 4 files changed +6
-23
lines changed
1-Call-MSGraph/daemon-console Expand file tree Collapse file tree 4 files changed +6
-23
lines changed Original file line number Diff line number Diff line change 1414 <PackageReference Include =" Microsoft.Extensions.Configuration" Version =" 3.1.0" />
1515 <PackageReference Include =" Microsoft.Extensions.Configuration.Binder" Version =" 3.1.0" />
1616 <PackageReference Include =" Microsoft.Extensions.Configuration.Json" Version =" 3.1.0" />
17- <PackageReference Include =" Microsoft.Identity.Client" Version =" 4.16.0 " />
17+ <PackageReference Include =" Microsoft.Identity.Client" Version =" 4.16.1 " />
1818 <PackageReference Include =" Newtonsoft.Json" Version =" 12.0.3" />
1919 </ItemGroup >
2020
Original file line number Diff line number Diff line change 55using Microsoft . AspNetCore . Authorization ;
66using Microsoft . AspNetCore . Http ;
77using Microsoft . AspNetCore . Mvc ;
8+ using Microsoft . Identity . Web . Resource ;
89using Newtonsoft . Json ;
910using TodoList_WebApi . Models ;
1011
@@ -31,9 +32,9 @@ public TodoListController()
3132
3233 // GET: api/todolist
3334 [ HttpGet ]
34- [ Authorize ( Policy = "DaemonAppRole" ) ]
3535 public IActionResult Get ( )
3636 {
37+ HttpContext . ValidateAppRole ( "DaemonAppRole" ) ;
3738 return Ok ( TodoStore . Values ) ;
3839 }
3940 }
Original file line number Diff line number Diff line change @@ -21,26 +21,8 @@ public Startup(IConfiguration configuration)
2121 // This method gets called by the runtime. Use this method to add services to the container.
2222 public void ConfigureServices ( IServiceCollection services )
2323 {
24- // This is required to be instantiated before the OpenIdConnectOptions starts getting configured.
25- // By default, the claims mapping will map claim names in the old format to accommodate older SAML applications.
26- // 'http://schemas.microsoft.com/ws/2008/06/identity/claims/role' instead of 'roles'
27- // This flag ensures that the ClaimsIdentity claims collection will be built from the claims in the token
28- JwtSecurityTokenHandler . DefaultMapInboundClaims = false ;
29-
30- services . AddProtectedWebApi ( Configuration ) ;
31-
32- // Additional configuration
33- services . Configure < JwtBearerOptions > ( JwtBearerDefaults . AuthenticationScheme , options =>
34- {
35- options . TokenValidationParameters . RoleClaimType = "roles" ;
36- } ) ;
37-
38- // Creating policies that wraps the authorization requirements.
39- services . AddAuthorization ( options =>
40- {
41- // The application should only allow tokens which roles claim contains "DaemonAppRole")
42- options . AddPolicy ( "DaemonAppRole" , policy => policy . RequireRole ( "DaemonAppRole" ) ) ;
43- } ) ;
24+ services . AddAuthentication ( JwtBearerDefaults . AuthenticationScheme )
25+ . AddMicrosoftWebApi ( Configuration ) ;
4426
4527 services . AddControllers ( ) ;
4628 }
Original file line number Diff line number Diff line change 1414 <PackageReference Include =" Microsoft.Extensions.Configuration" Version =" 3.0.0" />
1515 <PackageReference Include =" Microsoft.Extensions.Configuration.Binder" Version =" 3.0.0" />
1616 <PackageReference Include =" Microsoft.Extensions.Configuration.Json" Version =" 3.0.0" />
17- <PackageReference Include =" Microsoft.Identity.Client" Version =" 4.16.0 " />
17+ <PackageReference Include =" Microsoft.Identity.Client" Version =" 4.16.1 " />
1818 <PackageReference Include =" Newtonsoft.Json" Version =" 11.0.2" />
1919 </ItemGroup >
2020
You can’t perform that action at this time.
0 commit comments