Skip to content

Commit f3518ad

Browse files
committed
Added a new post: New Project: Required Auth Analyzer
1 parent 10316f9 commit f3518ad

File tree

1 file changed

+19
-0
lines changed
  • src/ProgrammerAl.Site.Content/Posts/20250126_RequiredAuthRoslynAnalyzer

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Title: "New Project: Required Auth Analyzer"
2+
Published: 2025/02/09
3+
Tags:
4+
- Project
5+
- C#
6+
- Roslyn Analyzer
7+
---
8+
9+
## New Project: Required Auth Analyzer
10+
11+
I've always worried about missing an auth attribute on an ASP.NET Core endpoint and leaving the API open to anyone to abuse. You can set a flag to require auth for the entire site, and then set auth requirements for other endpoints, but that doesn't work when you have more complex auth requirements. For example, different endpoints requiring different levels of authorization. Some endpoitns are anonymous, some require a signed in user, some require an admin, etc.
12+
13+
So I created a C# Roslyn Analyzer to check each ASP.NET Core endpoint and require it to have an attribute which specifies what auth, if any, is required to access that endpoint. It's makes code more verbose, but I feel it's easier for developers to remember what is required for the endpoint by just looking at the code in one spot. It's all right there on the endpoint.
14+
15+
The full details are in the project README at: https://github.com/ProgrammerAL/required-auth.analyzer.
16+
17+
## NuGet Package
18+
19+
The NuGet package is hosted on nuget.org. You can get it from: https://www.nuget.org/packages/ProgrammerAL.Analyzers.RequiredAuthAnalyzer

0 commit comments

Comments
 (0)