| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.ExternalAuthentication.Constants; |
| | | 3 | | using Elsa.ExternalAuthentication.Models; |
| | | 4 | | using Elsa.ExternalAuthentication.Services; |
| | | 5 | | using FastEndpoints; |
| | | 6 | | using Microsoft.AspNetCore.Builder; |
| | | 7 | | using Microsoft.AspNetCore.RateLimiting; |
| | | 8 | | |
| | | 9 | | namespace Elsa.ExternalAuthentication.Endpoints.Broker; |
| | | 10 | | |
| | | 11 | | internal sealed class CompleteCallback(IExternalAuthenticationBroker broker) : ElsaEndpoint<CompleteCallbackRequest> |
| | | 12 | | { |
| | | 13 | | public override void Configure() |
| | | 14 | | { |
| | | 15 | | Get("/external-authentication/callback/{connectionKey}"); |
| | | 16 | | AllowAnonymous(); |
| | | 17 | | Options(x => x.RequireRateLimiting(ExternalAuthenticationRateLimitPolicyNames.ProviderCallback)); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public override async Task HandleAsync(CompleteCallbackRequest request, CancellationToken cancellationToken) |
| | | 21 | | { |
| | | 22 | | var parameters = HttpContext.Request.Query.ToDictionary(x => x.Key, x => (IReadOnlyCollection<string>)x.Value.Wh |
| | | 23 | | var result = await broker.CompleteCallbackAsync(Route<string>("connectionKey") ?? request.ConnectionKey ?? strin |
| | | 24 | | if (result.Error is { } error) |
| | | 25 | | { |
| | | 26 | | if (result.RedirectUri is not null) |
| | | 27 | | { |
| | | 28 | | await Send.RedirectAsync(result.RedirectUri.ToString(), false, true); |
| | | 29 | | return; |
| | | 30 | | } |
| | | 31 | | await BrokerEndpointSupport.SendErrorAsync(Send, error, cancellationToken); |
| | | 32 | | return; |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | await Send.RedirectAsync(result.RedirectUri!.ToString(), false, true); |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | internal sealed class CompleteCallbackRequest |
| | | 40 | | { |
| | 1 | 41 | | public string? ConnectionKey { get; set; } |
| | 1 | 42 | | public string? State { get; set; } |
| | | 43 | | } |