-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from Lombiq/issue/OFFI-126
OFFI-126: Adding some extensions to handle api calls
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Lombiq.HelpfulLibraries.AspNetCore/Extensions/EndpointConventionBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Routing; | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Lombiq.HelpfulLibraries.AspNetCore.Extensions; | ||
|
||
public static class EndpointConventionBuilderExtensions | ||
{ | ||
public static IEndpointConventionBuilder RequireApiAuthorization(this IEndpointConventionBuilder builder) | ||
{ | ||
builder.RequireAuthorization(policy => | ||
policy.RequireAuthenticatedUser().AddAuthenticationSchemes("Api")); | ||
return builder; | ||
} | ||
|
||
public static IEndpointConventionBuilder DefaultSettings(this IEndpointConventionBuilder builder) => | ||
builder.DisableAntiforgery().RequireApiAuthorization(); | ||
|
||
public static RouteHandlerBuilder MapGetWithDefaultSettings( | ||
this IEndpointRouteBuilder builder, | ||
[StringSyntax("Route")] string pattern, | ||
Delegate handler) | ||
{ | ||
var router = builder.MapGet(pattern, handler); | ||
router.DefaultSettings(); | ||
return router; | ||
} | ||
|
||
public static RouteHandlerBuilder MapPostWithDefaultSettings( | ||
this IEndpointRouteBuilder builder, | ||
[StringSyntax("Route")] string pattern, | ||
Delegate handler) | ||
{ | ||
var router = builder.MapPost(pattern, handler); | ||
router.DefaultSettings(); | ||
return router; | ||
} | ||
|
||
public static RouteHandlerBuilder MapPutWithDefaultSettings( | ||
this IEndpointRouteBuilder builder, | ||
[StringSyntax("Route")] string pattern, | ||
Delegate handler) | ||
{ | ||
var router = builder.MapPut(pattern, handler); | ||
router.DefaultSettings(); | ||
return router; | ||
} | ||
|
||
public static RouteHandlerBuilder MapDeleteWithDefaultSettings( | ||
this IEndpointRouteBuilder builder, | ||
[StringSyntax("Route")] string pattern, | ||
Delegate handler) | ||
{ | ||
var router = builder.MapDelete(pattern, handler); | ||
router.DefaultSettings(); | ||
return router; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters