Initial Commit ...
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using IdentityModel;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace xIdentityService.Extensions {
|
||||
public static class AuthorizationPolicyBuilderExtensions {
|
||||
/// <summary>
|
||||
/// Adds a policy to check for required scopes.
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <param name="scope">List of any required scopes. The token must contain at least one of the listed scopes.</param>
|
||||
/// <returns></returns>
|
||||
public static AuthorizationPolicyBuilder RequireScope (this AuthorizationPolicyBuilder builder, params string[] scope) {
|
||||
return builder.RequireClaim (JwtClaimTypes.Scope, scope);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper for creating scope-related policies
|
||||
/// </summary>
|
||||
public static class ScopePolicy {
|
||||
/// <summary>
|
||||
/// Creates a policy to check for required scopes.
|
||||
/// </summary>
|
||||
/// <param name="scopes">List of any required scopes. The token must contain at least one of the listed scopes.</param>
|
||||
/// <returns></returns>
|
||||
public static AuthorizationPolicy Create (params string[] scopes) {
|
||||
return new AuthorizationPolicyBuilder ()
|
||||
.RequireScope (scopes)
|
||||
.Build ();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user