dotnet / dotnet/aspnetcore

[Refactoring] Move local authz policies to global authz policies

Open
#45,220 3 comments 0 reactions 0 assignees View on GitHub
analyzer area-auth help wanted
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

## Background and Motivation

In .NET 7, we introduced the `RequireAuthorization` extension method that allowed a user to construct and add an authorization policy onto an endpoint with on invocation. There are scenarios were users would want to factor these policies out to from endpoint-specific (local) to global policies on the application.

## Proposed Refactoring

### Refactoring Behavior and Message

When right-clicking on a line of code with a `RequireAuthorization` option the refactoring will be provided with the following message:

> Convert to global authorization policy

## Usage Scenarios

```csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAuthorization();

var app = builder.Build();

app.UseAuthorization();

app.MapGet("/", () => "Hello world!")
.RequireAuthorization(policy => p.RequireClaim("scope", "api-access")));

app.Run();
```

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.