dotnet / dotnet/aspnetcore

Add a `Scope` property to the `Authorize` attribute

Open
#55,973 0 comments 2 reactions 0 assignees View on GitHub
api-suggestion area-auth enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

## Background and Motivation

Make it easy to restrict access to a resource to authenticated users carrying a scope in their claims.

## Proposed API

```diff
namespace Microsoft.AspNetCore.Authorization;

public class AuthorizeAttribute : Attribute, Microsoft.AspNetCore.Authorization.IAuthorizeData
{
+ ///
+ /// Gets or sets the scope name that determines access to the resource.
+ ///
+ public string? Scope { get; set; }
}
```

## Usage Examples

```csharp
[Authorize(Scope = "read:project")]
public class HomeController : Controller
{
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.