-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to check custom header when receiving http endpoint request (
#4230) * Add option to check custom header when receiving http endpoint request * Fix grammatic error * Add header authorization example to sample project --------- Co-authored-by: Tanel Kuhi <tanel.kuhi@helmes.com>
- Loading branch information
Showing
5 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
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
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
24 changes: 24 additions & 0 deletions
24
src/activities/Elsa.Activities.Http/Services/CustomHeaderAuthorizationHandler.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,24 @@ | ||
using System.Threading.Tasks; | ||
using Elsa.Activities.Http.Contracts; | ||
using Elsa.Activities.Http.Models; | ||
|
||
namespace Elsa.Activities.Http.Services | ||
{ | ||
public class CustomHeaderAuthorizationHandler : IHttpEndpointAuthorizationHandler | ||
{ | ||
public async ValueTask<bool> AuthorizeAsync(AuthorizeHttpEndpointContext context) | ||
{ | ||
var httpContext = context.HttpContext; | ||
|
||
var cancellationToken = context.CancellationToken; | ||
var httpEndpoint = context.HttpEndpointActivity; | ||
var headerName = await httpEndpoint.EvaluatePropertyValueAsync(x => x.CustomHeaderName, cancellationToken); | ||
var expectedHeaderValue = await httpEndpoint.EvaluatePropertyValueAsync(x => x.CustomHeaderValue, cancellationToken); | ||
|
||
if (string.IsNullOrWhiteSpace(headerName) || string.IsNullOrWhiteSpace(expectedHeaderValue)) | ||
return true; | ||
|
||
return httpContext.Request.Headers[headerName] == expectedHeaderValue; | ||
} | ||
} | ||
} |
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