Skip to content

Commit 558884a

Browse files
committed
add minimal auth endpoint, remove savetokens, re-order things
1 parent 4c9e7f2 commit 558884a

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

docs/docs/v4/welcome/migrate-quick-steps.md

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,16 +1293,15 @@ using Steeltoe.Security.Authentication.CloudFoundry;
12931293
var builder = WebApplication.CreateBuilder(args);
12941294
builder.AddCloudFoundryConfiguration();
12951295
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+
})
13001300
.AddCookie(options => options.AccessDeniedPath = new PathString("/Home/AccessDenied"))
13011301
- .AddCloudFoundryOAuth(builder.Configuration);
13021302
+ .AddCloudFoundryOpenIdConnect(builder.Configuration);
13031303
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"));
13061305

13071306
var app = builder.Build();
13081307

@@ -1314,6 +1313,12 @@ app.UseForwardedHeaders(new ForwardedHeadersOptions
13141313
app.UseAuthentication();
13151314
app.UseAuthorization();
13161315

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");
13171322
```
13181323

13191324
### OpenID Connect
@@ -1341,27 +1346,25 @@ appsettings.json:
13411346
- "Oauth2": {
13421347
- "Client": {
13431348
- "Authority": "http://localhost:8080/uaa",
1344-
- "CallbackPath": "/signin-oidc",
1345-
- "ClientId": "steeltoesamplesclient",
1346-
- "ClientSecret": "client_secret",
13471349
- "MetadataAddress": "http://localhost:8080/.well-known/openid-configuration",
13481350
- "RequireHttpsMetadata": false,
1349-
- "SaveTokens": true,
1350-
- "AdditionalScopes": "sampleapi.read"
1351+
- "AdditionalScopes": "sampleapi.read",
1352+
- "CallbackPath": "/signin-oidc",
1353+
- "ClientId": "steeltoesamplesclient",
1354+
- "ClientSecret": "client_secret"
13511355
- }
13521356
- }
13531357
- }
13541358
+ "Authentication": {
13551359
+ "Schemes": {
13561360
+ "OpenIdConnect": {
13571361
+ "Authority": "http://localhost:8080/uaa",
1358-
+ "CallbackPath": "/signin-oidc",
1359-
+ "ClientId": "steeltoesamplesclient",
1360-
+ "ClientSecret": "client_secret",
13611362
+ "MetadataAddress": "http://localhost:8080/.well-known/openid-configuration",
13621363
+ "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"
13651368
+ }
13661369
+ }
13671370
+ }
@@ -1388,17 +1391,16 @@ var builder = WebApplication.CreateBuilder(args);
13881391
builder.AddCloudFoundryConfiguration();
13891392
+builder.Configuration.AddCloudFoundryServiceBindings();
13901393
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+
})
13961399
.AddCookie(options => options.AccessDeniedPath = new PathString("/Home/AccessDenied"))
13971400
- .AddCloudFoundryOpenIdConnect(builder.Configuration);
13981401
+ .AddOpenIdConnect().ConfigureOpenIdConnectForCloudFoundry();
13991402
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"));
14021404

14031405
var app = builder.Build();
14041406

@@ -1409,6 +1411,13 @@ var app = builder.Build();
14091411

14101412
app.UseAuthentication();
14111413
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");
14121421
```
14131422

14141423
### JWT Bearer
@@ -1515,6 +1524,19 @@ Project file:
15151524
</Project>
15161525
```
15171526

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+
15181540
Program.cs (server-side):
15191541

15201542
```diff
@@ -1559,19 +1581,6 @@ app.MapGet("/test-same-space", async httpContext =>
15591581
> The code shown above is provided for compatibility between the versions. The preferred header name is `X-Client-Cert`.
15601582
> In Steeltoe 4.0, the default header is `X-Client-Cert`, so the parameter can be omitted if cross-compatibility is not required.
15611583
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-
15751584
Program.cs (client-side):
15761585

15771586
```diff

0 commit comments

Comments
 (0)