| | | 1 | | using Elsa.ExternalAuthentication.Models; |
| | | 2 | | |
| | | 3 | | namespace Elsa.ExternalAuthentication.Services; |
| | | 4 | | |
| | | 5 | | /// <summary>Builds Elsa-owned upstream callback URIs without allowing a configured base path to be discarded.</summary> |
| | | 6 | | public static class ExternalAuthenticationCallbackUris |
| | | 7 | | { |
| | | 8 | | /// <summary>Returns the provider callback for a normal external sign-in or an administrator preview.</summary> |
| | 82 | 9 | | public static Uri GetAuthorizationCallbackUri(Uri externalCallbackBaseUri, IdentityProviderConnection connection, Br |
| | 82 | 10 | | { |
| | 45 | 11 | | BrokerTransactionPurpose.ExternalSignIn => AppendPath(externalCallbackBaseUri, $"external-authentication/callbac |
| | 37 | 12 | | BrokerTransactionPurpose.Preview => AppendPath(externalCallbackBaseUri, $"external-authentication/previews/callb |
| | 0 | 13 | | _ => throw new InvalidOperationException($"Broker transaction purpose '{purpose}' cannot initiate an upstream au |
| | 82 | 14 | | }; |
| | | 15 | | |
| | | 16 | | /// <summary>Returns the provider callback for a broker-initiated upstream logout.</summary> |
| | | 17 | | public static Uri GetLogoutCallbackUri(Uri externalCallbackBaseUri, string connectionKey) => |
| | 2 | 18 | | AppendPath(externalCallbackBaseUri, $"external-authentication/logout/callback/{Uri.EscapeDataString(ConnectionRe |
| | | 19 | | |
| | | 20 | | private static Uri AppendPath(Uri externalCallbackBaseUri, string relativePath) |
| | | 21 | | { |
| | 84 | 22 | | ArgumentNullException.ThrowIfNull(externalCallbackBaseUri); |
| | | 23 | | |
| | 84 | 24 | | var builder = new UriBuilder(externalCallbackBaseUri) |
| | 84 | 25 | | { |
| | 84 | 26 | | Path = $"{externalCallbackBaseUri.AbsolutePath.TrimEnd('/')}/{relativePath.TrimStart('/')}", |
| | 84 | 27 | | Query = string.Empty, |
| | 84 | 28 | | Fragment = string.Empty, |
| | 84 | 29 | | Port = externalCallbackBaseUri.IsDefaultPort ? -1 : externalCallbackBaseUri.Port |
| | 84 | 30 | | }; |
| | 84 | 31 | | return builder.Uri; |
| | | 32 | | } |
| | | 33 | | } |