-
Notifications
You must be signed in to change notification settings - Fork 25k
Update claims-based authorization samples to use AddAuthorizationBuilder() #36675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…tion Co-authored-by: wadepickett <10985336+wadepickett@users.noreply.github.com>
Updated README to reflect ASP.NET Core 7.0 features and structure.
wadepickett
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed two mistakes copilot made, otherwise looks good now.
|
Fixed several issues, but now suddely Policheck is blocking with several false positive hits: It is throwing multiple errors on jquery-validation files. Which it should not even be reading since that is 3rd party. Looking into finding a way to exclude Policheck of certain exceptions for anything on the this path: Example path: One example error code: @guardrex & tdykstra, just a heads up. I'm trying to resolve this with the Policheck tool folks today. Looks like something was checked in or at least distributed new today that is going to keep us from successfully building anything that happens to have a jQuery library in it. Others are seeing this as well for blocking some Azure python related code from passing. |
forcing a rebuild with a minor change to the ms.date to test policheck.
Code samples violated ASP0025 by using
AddAuthorization(options => ...). .NET 7+ recommendsAddAuthorizationBuilder().Changes
AddAuthorizationBuilder()patternExample
Before (6.x - triggers ASP0025):
After (7.x - compliant):
Users viewing docs for .NET 7+ see the recommended pattern; .NET 6 users see the original pattern.
Original prompt
This section details on the original issue you should resolve
<issue_title>Code sample for Claims-based authorization violate ASP0025</issue_title>
<issue_description>### Description
The code samples from https://learn.microsoft.com/en-us/aspnet/core/security/authorization/claims?view=aspnetcore-10.0#adding-claims-checks, namely:
violates https://learn.microsoft.com/en-us/aspnet/core/diagnostics/asp0025?view=aspnetcore-10.0 which suggests using this instead:
Page URL
https://learn.microsoft.com/en-us/aspnet/core/security/authorization/claims?view=aspnetcore-10.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/security/authorization/claims.md
Document ID
50736569-fc04-ec6d-7b33-a3e0c860b1ed
Platform Id
53152e93-cef7-e267-13ca-474a7717e614
Article author
@wadepickett
Metadata
Related Issues</issue_description>
<agent_instructions>Pay special attention to versioning of samles and documenation. Previous working versions must be maintained. </agent_instructions>
Comments on the Issue (you are @copilot in this section)
@wadepickett @abatishchev, thanks very much for pointing this issue out and the details for fixing. Greatly appreciated! @wadepickett ## 🤖 AI Triage SummaryThis preliminary assessment report was run by: @wadepickett
Date: 2026-01-23
Issue: 36666
Model: GitHub Copilot
Issue Analysis: Code samples use
AddAuthorizationinstead of recommendedAddAuthorizationBuilder✅ Issue Validation
Status: Valid and actionable
📋 Issue Summary
The code samples in the Claims-based authorization documentation use
builder.Services.AddAuthorization(options => ...)pattern which triggers analyzer warning ASP0025. The recommended approach since .NET 7+ is to useAddAuthorizationBuilder()which is more concise and follows current best practices.📁 Potentially Affected Files
aspnetcore/security/authorization/claims/samples/6.x/WebAll/Program.cssnippetregion - EmployeeOnly policyaspnetcore/security/authorization/claims/samples/6.x/WebAll/Program.cssnippet2region - Founders policy📝 Preliminary Change Assessment
Potential Code Sample Updates
[Added corected instruction here from Wade Pickett ]
A new 7.x code sample in its own 7.x folder needs to be created rather than changing the original 6.x sample which must be maintained. - Wade Pickett
File:
aspnetcore/security/authorization/claims/samples/6.x/WebAll/Program.csLocation: Lines 10-13 (
snippetregion)Type: Replacement
Current code (lines 10-13):
Suggested direction:
A new 7.x code sample in its own 7.x folder needs to be created rather than changing the original 6.x sample which must be maintained. - Wade Pickett
File: [
aspnetcore/security/authorization/claims/samples/6.x/WebAll/Program.cs](https://github.com/dotnet/AspNetCore.Docs/blob/11b12a998f11ab97e8afef4aadba20e08790...✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews