1010namespace Shared . Authorisation
1111{
1212 public static class AuthorizationExtensions {
13+
14+ public static class PolicyNames {
15+ public const string ClientCredentialsOnlyPolicy = "ClientCredentialsOnly" ;
16+ public const string PasswordTokenOnlyPolicy = "PasswordToken" ;
17+ public const string AuthorisedTokenPolicy = "AnyTokenType" ;
18+ }
19+
20+ public static IServiceCollection AddAuthorisedTokenPolicy ( this IServiceCollection services )
21+ {
22+ services . AddAuthorization ( options => {
23+ options . AddPolicy ( PolicyNames . AuthorisedTokenPolicy , policy => policy . RequireAuthenticatedUser ( ) ) ;
24+ } ) ;
25+
26+ return services ;
27+ }
28+
1329 public static IServiceCollection AddClientCredentialsHandler ( this IServiceCollection services ) {
1430 services . AddSingleton < IAuthorizationHandler , ClientCredentialsHandler > ( ) ;
1531 return services ;
1632 }
1733
1834 public static IServiceCollection AddClientCredentialsOnlyPolicy ( this IServiceCollection services ) {
1935 services . AddAuthorization ( options => {
20- options . AddPolicy ( "ClientCredentialsOnly" , policy =>
36+ options . AddPolicy ( PolicyNames . ClientCredentialsOnlyPolicy , policy =>
2137 policy . Requirements . Add ( new ClientCredentialsRequirement ( ) ) ) ;
2238 } ) ;
2339
@@ -34,7 +50,7 @@ public static IServiceCollection AddPasswordTokenPolicy(this IServiceCollection
3450 {
3551 services . AddAuthorization ( options =>
3652 {
37- options . AddPolicy ( "PasswordToken" , policy =>
53+ options . AddPolicy ( PolicyNames . PasswordTokenOnlyPolicy , policy =>
3854 policy . Requirements . Add ( new PasswordTokenRequirement ( ) ) ) ;
3955 } ) ;
4056
0 commit comments