Skip to content

Commit 7b3c9e3

Browse files
committed
Fix scopes, strange effects with Openiddict
1 parent e2d032e commit 7b3c9e3

4 files changed

Lines changed: 10 additions & 23 deletions

File tree

ResourceServer/HostingExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Authentication.JwtBearer;
22
using Microsoft.AspNetCore.Authorization;
33
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.IdentityModel.Logging;
45
using NetEscapades.AspNetCore.SecurityHeaders.Infrastructure;
56
using ResourceServer.Model;
67
using ResourceServer.Repositories;
@@ -99,11 +100,13 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde
99100
{
100101
options.AddPolicy("dataEventRecordsAdmin", policyAdmin =>
101102
{
102-
policyAdmin.RequireClaim("role", "dataEventRecords.admin");
103+
//policyAdmin.RequireClaim("role", "dataEventRecords.admin");
104+
policyAdmin.Requirements.Add(new RequireScope());
103105
});
104106
options.AddPolicy("dataEventRecordsUser", policyUser =>
105107
{
106-
policyUser.RequireClaim("role", "dataEventRecords.user");
108+
//policyUser.RequireClaim("role", "dataEventRecords.user");
109+
policyUser.Requirements.Add(new RequireScope());
107110
});
108111
options.AddPolicy("dataEventRecordsPolicy", policyUser =>
109112
{
@@ -120,6 +123,8 @@ public static WebApplication ConfigureServices(this WebApplicationBuilder builde
120123

121124
public static WebApplication ConfigurePipeline(this WebApplication app)
122125
{
126+
IdentityModelEventSource.ShowPII = true;
127+
123128
var deploySwaggerUI = app.Configuration.GetValue<bool>("DeploySwaggerUI");
124129
app.UseCors("AllowAllOrigins");
125130

ResourceServer/Properties/launchSettings.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
{
2-
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
5-
"iisExpress": {
6-
"applicationUrl": "https://localhost:44390/",
7-
"sslPort": 44390
8-
}
9-
},
102
"profiles": {
11-
"IIS Express": {
12-
"commandName": "IISExpress",
13-
"launchBrowser": true,
14-
"launchUrl": "https://localhost:44390/swagger",
15-
"environmentVariables": {
16-
"ASPNETCORE_ENVIRONMENT": "Development"
17-
}
18-
},
193
"ResourceServer": {
204
"commandName": "Project",
215
"launchUrl": "https://localhost:44390/swagger",

ResourceServer/RequireScopeHandler.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ protected override Task HandleRequirementAsync(
1212
{
1313
throw new ArgumentNullException(nameof(context));
1414
}
15-
16-
1715
if (requirement == null)
1816
{
1917
throw new ArgumentNullException(nameof(requirement));
@@ -22,7 +20,7 @@ protected override Task HandleRequirementAsync(
2220
var scopeClaim = context.User.Claims.FirstOrDefault(t => t.Type == "scope");
2321

2422

25-
if (scopeClaim != null && (context.User.HasScope("dataEventRecords")))
23+
if (scopeClaim != null && (scopeClaim.Value.Contains("dataEventRecords")))
2624
{
2725
context.Succeed(requirement);
2826
}

ResourceServer/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"DefaultConnection": "Data Source=dataeventrecords.sqlite"
44
},
55
"ProfileApiConfigurations": {
6-
"Authority": "https://localhost:44337",
7-
"Audience": "dataEventRecordsApi"
6+
"Authority": "https://localhost:44395/",
7+
"Audience": "rs_dataEventRecordsApi"
88
},
99
"DeploySwaggerUI": true,
1010
"Serilog": {

0 commit comments

Comments
 (0)