https://github.com/pdmlab/scopeauthorizationrequirement
Scope Claim authorization Requirement for ASP.NET Core
https://github.com/pdmlab/scopeauthorizationrequirement
asp-net-core authorization claims jwt oidc scopes
Last synced: 8 months ago
JSON representation
Scope Claim authorization Requirement for ASP.NET Core
- Host: GitHub
- URL: https://github.com/pdmlab/scopeauthorizationrequirement
- Owner: PDMLab
- License: mit
- Created: 2021-01-09T22:03:16.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-15T01:19:40.000Z (over 4 years ago)
- Last Synced: 2025-02-03T23:36:17.499Z (8 months ago)
- Topics: asp-net-core, authorization, claims, jwt, oidc, scopes
- Language: C#
- Homepage: https://www.nuget.org/packages/ScopeAuthorizationRequirement/
- Size: 15.6 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ScopeAuthorizationRequirement
This package provides a `scope` claim authorization requirement for ASP.NET Core.It handles multiple space delimited `scope` claims according to https://tools.ietf.org/html/rfc6749#section-3.3 (which the ASP.NET Core `RequireClaim` Requirement does not, hence can't be used e.g. with AWS Cognito when using multiple scopes).
## Installation
```bash
dotnet add package ScopeAuthorizationRequirement
```## Usage
### Single scope required
```csharp
services.AddAuthorization(options =>
{
options.AddPolicy("openid", policy =>
{
policy.RequireAuthenticatedUser();
policy.RequireScope("openid");
});
});
```### Multiple scopes required
```csharp
services.AddAuthorization(options =>
{
options.AddPolicy("openid+profile", policy =>
{
policy.RequireAuthenticatedUser();
policy.RequireScopes(NonEmptyList.Create("openid", "profile"));
});
});
```