@@ -1293,16 +1293,15 @@ using Steeltoe.Security.Authentication.CloudFoundry;
1293
1293
var builder = WebApplication.CreateBuilder(args);
1294
1294
builder.AddCloudFoundryConfiguration();
1295
1295
builder.Services.AddAuthentication(options =>
1296
- {
1297
- options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
1298
- options.DefaultChallengeScheme = CloudFoundryDefaults.AuthenticationScheme;
1299
- })
1296
+ {
1297
+ options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
1298
+ options.DefaultChallengeScheme = CloudFoundryDefaults.AuthenticationScheme;
1299
+ })
1300
1300
.AddCookie(options => options.AccessDeniedPath = new PathString("/Home/AccessDenied"))
1301
1301
- .AddCloudFoundryOAuth(builder.Configuration);
1302
1302
+ .AddCloudFoundryOpenIdConnect(builder.Configuration);
1303
1303
builder.Services.AddAuthorizationBuilder()
1304
- .AddPolicy("read", policy => policy.RequireClaim("scope", "sampleapi.read"))
1305
- .AddPolicy("write", policy => policy.RequireClaim("scope", "sampleapi.write"));
1304
+ .AddPolicy("read", policy => policy.RequireClaim("scope", "sampleapi.read"));
1306
1305
1307
1306
var app = builder.Build();
1308
1307
@@ -1314,6 +1313,12 @@ app.UseForwardedHeaders(new ForwardedHeadersOptions
1314
1313
app.UseAuthentication();
1315
1314
app.UseAuthorization();
1316
1315
1316
+ app.MapGet("/test-auth", async httpContext =>
1317
+ {
1318
+ httpContext.Response.StatusCode = 200;
1319
+ httpContext.Response.ContentType = "text/plain";
1320
+ await httpContext.Response.WriteAsync("You are logged in and carry the required claim.");
1321
+ }).RequireAuthorization("read");
1317
1322
```
1318
1323
1319
1324
### OpenID Connect
@@ -1341,27 +1346,25 @@ appsettings.json:
1341
1346
- "Oauth2": {
1342
1347
- "Client": {
1343
1348
- "Authority": "http://localhost:8080/uaa",
1344
- - "CallbackPath": "/signin-oidc",
1345
- - "ClientId": "steeltoesamplesclient",
1346
- - "ClientSecret": "client_secret",
1347
1349
- "MetadataAddress": "http://localhost:8080/.well-known/openid-configuration",
1348
1350
- "RequireHttpsMetadata": false,
1349
- - "SaveTokens": true,
1350
- - "AdditionalScopes": "sampleapi.read"
1351
+ - "AdditionalScopes": "sampleapi.read",
1352
+ - "CallbackPath": "/signin-oidc",
1353
+ - "ClientId": "steeltoesamplesclient",
1354
+ - "ClientSecret": "client_secret"
1351
1355
- }
1352
1356
- }
1353
1357
- }
1354
1358
+ "Authentication": {
1355
1359
+ "Schemes": {
1356
1360
+ "OpenIdConnect": {
1357
1361
+ "Authority": "http://localhost:8080/uaa",
1358
- + "CallbackPath": "/signin-oidc",
1359
- + "ClientId": "steeltoesamplesclient",
1360
- + "ClientSecret": "client_secret",
1361
1362
+ "MetadataAddress": "http://localhost:8080/.well-known/openid-configuration",
1362
1363
+ "RequireHttpsMetadata": false,
1363
- + "SaveTokens": true,
1364
- + "Scope": [ "openid", "sampleapi.read" ]
1364
+ + "Scope": [ "openid", "sampleapi.read" ],
1365
+ + "CallbackPath": "/signin-oidc",
1366
+ + "ClientId": "steeltoesamplesclient",
1367
+ + "ClientSecret": "client_secret"
1365
1368
+ }
1366
1369
+ }
1367
1370
+ }
@@ -1388,17 +1391,16 @@ var builder = WebApplication.CreateBuilder(args);
1388
1391
builder.AddCloudFoundryConfiguration();
1389
1392
+ builder.Configuration.AddCloudFoundryServiceBindings();
1390
1393
builder.Services.AddAuthentication(options =>
1391
- {
1392
- options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
1393
- - options.DefaultChallengeScheme = CloudFoundryDefaults.AuthenticationScheme;
1394
- + options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
1395
- })
1394
+ {
1395
+ options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
1396
+ - options.DefaultChallengeScheme = CloudFoundryDefaults.AuthenticationScheme;
1397
+ + options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
1398
+ })
1396
1399
.AddCookie(options => options.AccessDeniedPath = new PathString("/Home/AccessDenied"))
1397
1400
- .AddCloudFoundryOpenIdConnect(builder.Configuration);
1398
1401
+ .AddOpenIdConnect().ConfigureOpenIdConnectForCloudFoundry();
1399
1402
builder.Services.AddAuthorizationBuilder()
1400
- .AddPolicy("read", policy => policy.RequireClaim("scope", "sampleapi.read"))
1401
- .AddPolicy("write", policy => policy.RequireClaim("scope", "sampleapi.write"));
1403
+ .AddPolicy("read", policy => policy.RequireClaim("scope", "sampleapi.read"));
1402
1404
1403
1405
var app = builder.Build();
1404
1406
@@ -1409,6 +1411,13 @@ var app = builder.Build();
1409
1411
1410
1412
app.UseAuthentication();
1411
1413
app.UseAuthorization();
1414
+
1415
+ app.MapGet("/test-auth", async httpContext =>
1416
+ {
1417
+ httpContext.Response.StatusCode = 200;
1418
+ httpContext.Response.ContentType = "text/plain";
1419
+ await httpContext.Response.WriteAsync("You are logged in and carry the required claim.");
1420
+ }).RequireAuthorization("read");
1412
1421
```
1413
1422
1414
1423
### JWT Bearer
@@ -1515,6 +1524,19 @@ Project file:
1515
1524
</Project>
1516
1525
```
1517
1526
1527
+ launchsettings.json (server-side):
1528
+
1529
+ ``` diff
1530
+ {
1531
+ "profiles": {
1532
+ "http": {
1533
+ "commandName": "Project",
1534
+ "applicationUrl": "https://localhost:7107"
1535
+ }
1536
+ }
1537
+ }
1538
+ ```
1539
+
1518
1540
Program.cs (server-side):
1519
1541
1520
1542
``` diff
@@ -1559,19 +1581,6 @@ app.MapGet("/test-same-space", async httpContext =>
1559
1581
> The code shown above is provided for compatibility between the versions. The preferred header name is ` X-Client-Cert ` .
1560
1582
> In Steeltoe 4.0, the default header is ` X-Client-Cert ` , so the parameter can be omitted if cross-compatibility is not required.
1561
1583
1562
- launchsettings.json (server-side):
1563
-
1564
- ``` diff
1565
- {
1566
- "profiles": {
1567
- "http": {
1568
- "commandName": "Project",
1569
- "applicationUrl": "https://localhost:7107"
1570
- }
1571
- }
1572
- }
1573
- ```
1574
-
1575
1584
Program.cs (client-side):
1576
1585
1577
1586
``` diff
0 commit comments