Skip to content

Commit

Permalink
Update the minimal API samples to support POST for the authorization …
Browse files Browse the repository at this point in the history
…endpoint
  • Loading branch information
kevinchalet committed Mar 15, 2024
1 parent c969579 commit e405c7b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion samples/Dantooine/Dantooine.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/api/DantooineApi", [Authorize] () => new string[] { "data1", "data2" });
app.MapGet("api/DantooineApi", [Authorize] () => new string[] { "data1", "data2" });

app.Run();
4 changes: 2 additions & 2 deletions samples/Mimban/Mimban.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ await using (var scope = app.Services.CreateAsyncScope())
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/api", [Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
app.MapGet("api", [Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
(ClaimsPrincipal user) => user.Identity!.Name);

app.MapMethods("callback/login/github", [HttpMethods.Get, HttpMethods.Post], async (HttpContext context) =>
Expand All @@ -180,7 +180,7 @@ await using (var scope = app.Services.CreateAsyncScope())
return Results.SignIn(new ClaimsPrincipal(identity), properties);
});

app.MapGet("/authorize", async (HttpContext context) =>
app.MapMethods("authorize", [HttpMethods.Get, HttpMethods.Post], async (HttpContext context) =>
{
// Resolve the claims stored in the cookie created after the GitHub authentication dance.
// If the principal cannot be found, trigger a new challenge to redirect the user to GitHub.
Expand Down
2 changes: 1 addition & 1 deletion samples/Zirku/Zirku.Api1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/api", [Authorize] (ClaimsPrincipal user) => $"{user.Identity!.Name} is allowed to access Api1.");
app.MapGet("api", [Authorize] (ClaimsPrincipal user) => $"{user.Identity!.Name} is allowed to access Api1.");

app.Run();
2 changes: 1 addition & 1 deletion samples/Zirku/Zirku.Api2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/api", [Authorize] (ClaimsPrincipal user) => $"{user.Identity!.Name} is allowed to access Api2.");
app.MapGet("api", [Authorize] (ClaimsPrincipal user) => $"{user.Identity!.Name} is allowed to access Api2.");

app.Run();
4 changes: 2 additions & 2 deletions samples/Zirku/Zirku.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ async Task CreateScopesAsync()
app.UseAuthentication();
app.UseAuthorization();

app.MapGet("/api", [Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
app.MapGet("api", [Authorize(AuthenticationSchemes = OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme)]
(ClaimsPrincipal user) => user.Identity!.Name);

app.MapGet("/authorize", async (HttpContext context, IOpenIddictScopeManager manager) =>
app.MapMethods("authorize", [HttpMethods.Get, HttpMethods.Post], async (HttpContext context, IOpenIddictScopeManager manager) =>
{
// Retrieve the OpenIddict server request from the HTTP context.
var request = context.GetOpenIddictServerRequest();
Expand Down

0 comments on commit e405c7b

Please sign in to comment.