| | | 1 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 2 | | using Elsa.ExternalAuthentication.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.ExternalAuthentication.Permissions; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Grants only provider claim values explicitly bounded by configured literal permission names. |
| | | 8 | | /// </summary> |
| | | 9 | | public sealed class ClaimPassThroughPermissionGrantSource : IPermissionGrantSource |
| | | 10 | | { |
| | | 11 | | public const string SourceType = "claim-pass-through"; |
| | 6 | 12 | | public string Type => SourceType; |
| | | 13 | | |
| | 0 | 14 | | public PermissionGrantSourceDescriptor Describe() => new(Type, "Bounded claim pass-through", "Grants only projected |
| | | 15 | | |
| | | 16 | | public ValueTask<PermissionGrantResult> GetGrantsAsync(PermissionGrantContext context, CancellationToken cancellatio |
| | | 17 | | { |
| | 2 | 18 | | if (context.Selection.Settings.ValueKind != System.Text.Json.JsonValueKind.Object || !context.Selection.Settings |
| | 0 | 19 | | return ValueTask.FromResult(new PermissionGrantResult([], [])); |
| | | 20 | | |
| | 2 | 21 | | var claimType = claimTypeProperty.GetString(); |
| | 2 | 22 | | var boundary = PermissionGrantMappingSettings.ReadPassThroughPermissions(context.Selection.Settings); |
| | 2 | 23 | | if (string.IsNullOrWhiteSpace(claimType) || boundary.Count == 0 || !context.ProjectedClaims.TryGetValue(claimTyp |
| | 1 | 24 | | return ValueTask.FromResult(new PermissionGrantResult([], [])); |
| | | 25 | | |
| | 3 | 26 | | var grants = values.Where(boundary.Contains).OrderBy(x => x, StringComparer.Ordinal).Select(value => new Permiss |
| | 1 | 27 | | return ValueTask.FromResult(new PermissionGrantResult(grants, [])); |
| | | 28 | | } |
| | | 29 | | } |