| | | 1 | | using Elsa.ExternalAuthentication.Contracts; |
| | | 2 | | using Elsa.ExternalAuthentication.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.ExternalAuthentication.Permissions; |
| | | 5 | | |
| | | 6 | | public sealed class ClaimMappingPermissionGrantSource : IPermissionGrantSource |
| | | 7 | | { |
| | | 8 | | public const string SourceType = "claim-mapping"; |
| | 10 | 9 | | public string Type => SourceType; |
| | | 10 | | |
| | 0 | 11 | | public PermissionGrantSourceDescriptor Describe() => new(Type, "Claim mapping", "Grants explicitly mapped Elsa permi |
| | | 12 | | |
| | 5 | 13 | | public ValueTask<PermissionGrantResult> GetGrantsAsync(PermissionGrantContext context, CancellationToken cancellatio |
| | | 14 | | |
| | | 15 | | internal static PermissionGrantResult CreateResult(PermissionGrantContext context, string sourceType) |
| | | 16 | | { |
| | 7 | 17 | | var grants = PermissionGrantMappingSettings.Read(context.Selection.Settings) |
| | 7 | 18 | | .SelectMany(mapping => context.ProjectedClaims.TryGetValue(mapping.ClaimType, out var values) && values.Cont |
| | 10 | 19 | | ? mapping.Permissions.Select(permission => new PermissionGrant(permission, sourceType, $"{mapping.ClaimT |
| | 7 | 20 | | : []) |
| | 7 | 21 | | .ToArray(); |
| | 7 | 22 | | return new PermissionGrantResult(grants, []); |
| | | 23 | | } |
| | | 24 | | } |