| | 1 | | using Kestrun.Authentication; |
| | 2 | | using Microsoft.AspNetCore.Authorization; |
| | 3 | | using Microsoft.Extensions.Options; |
| | 4 | |
|
| | 5 | | namespace Kestrun.Claims; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// Copies <see cref="ClaimPolicyConfig"/> into <see cref="AuthorizationOptions"/> after configuration. |
| | 9 | | /// </summary> |
| | 10 | | /// <remarks> |
| | 11 | | /// Initializes a new instance of the <see cref="ClaimPolicyPostConfigurer"/> class. |
| | 12 | | /// </remarks> |
| | 13 | | /// <param name="scheme">The authentication scheme name.</param> |
| | 14 | | /// <param name="basics">The options monitor for <see cref="BasicAuthenticationOptions"/>.</param> |
| 8 | 15 | | public sealed class ClaimPolicyPostConfigurer( |
| 8 | 16 | | string scheme, |
| 8 | 17 | | IOptionsMonitor<IClaimsCommonOptions> basics) |
| | 18 | | : IPostConfigureOptions<AuthorizationOptions> |
| | 19 | | { |
| 8 | 20 | | private readonly string _scheme = scheme; |
| 8 | 21 | | private readonly IOptionsMonitor<IClaimsCommonOptions> _basics = basics; |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// Applies the <see cref="ClaimPolicyConfig"/> to the specified <see cref="AuthorizationOptions"/> after configurat |
| | 25 | | /// </summary> |
| | 26 | | /// <param name="name">The name of the options instance being configured. May be null.</param> |
| | 27 | | /// <param name="authz">The <see cref="AuthorizationOptions"/> instance to configure.</param> |
| | 28 | | public void PostConfigure(string? name, AuthorizationOptions authz) |
| | 29 | | { |
| | 30 | | // Only run once for the default options instance |
| 8 | 31 | | var claimCfg = _basics.Get(_scheme).ClaimPolicyConfig; |
| 8 | 32 | | claimCfg?.ToAuthzDelegate()?.Invoke(authz); |
| 8 | 33 | | } |
| | 34 | | } |