Authorization failed. These requirements were not met: RolesAuthorizationRequirement:User.IsInRole must be true for one of the following roles: (admin)
in the server log means the user was signed in, but none of their role claims matched
a role the policy asks for. The caller sees 403 Forbidden. In this test the
fix was a token that carries the role.
In this test the token was valid and had no role claim at all. A token from the same
endpoint with role = admin returned 200.
The error
What the client got, and the line the server console printed at Information
level from Microsoft.AspNetCore.Authorization.DefaultAuthorizationService:
PS> $token = curl.exe -s http://127.0.0.1:15630/token
PS> curl.exe -s -i -H "Authorization: Bearer $token" http://127.0.0.1:15630/reports
HTTP/1.1 403 Forbidden
Content-Length: 0
Date: Sat, 14 Nov 2026 01:26:32 GMT
Server: Kestrel
...
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed. These requirements were not met:
RolesAuthorizationRequirement:User.IsInRole must be true for one of the following roles: (admin)
With the template's appsettings.json (Microsoft.AspNetCore at
Warning) the same 403 printed nothing in the console. This entry under
Logging:LogLevel made the line appear:
...
"Microsoft.AspNetCore.Authorization": "Information"
...
Why it happens
The endpoint used a policy built with RequireRole("admin"):
...
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("AdminOnly", policy => policy.RequireRole("admin"));
});
...
app.MapGet("/reports", () => "Monthly report").RequireAuthorization("AdminOnly");
...
RequireRole adds the RolesAuthorizationRequirement that the log
names, and the list in brackets is the roles it accepts. The token passed
authentication, which is why the answer was 403 and not 401, and then failed this one
requirement. The test endpoint /token adds a role claim only
when it is called with ?role=admin; called without it, the token carried
sub and no role.
For a 403 where the token does carry the role, see the 403 post about RoleClaimType.
The fix
Here the fix was a token that carries the role:
PS> $adminToken = curl.exe -s "http://127.0.0.1:15630/token?role=admin"
PS> curl.exe -s -i -H "Authorization: Bearer $adminToken" http://127.0.0.1:15630/reports
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Sat, 14 Nov 2026 01:26:32 GMT
Server: Kestrel
Transfer-Encoding: chunked
Monthly report
The two runs: no role gave 403, role=admin gave 200. A third run tested the
spelling: a token with role=Admin, capital A, against
RequireRole("admin") also got 403 and the same log line, so the role value
in the token must match the name in brackets exactly, case included:
PS> $capToken = curl.exe -s "http://127.0.0.1:15630/token?role=Admin"
PS> curl.exe -s -i -H "Authorization: Bearer $capToken" http://127.0.0.1:15630/reports
HTTP/1.1 403 Forbidden
Content-Length: 0
Date: Sat, 14 Nov 2026 01:39:56 GMT
Server: Kestrel
...
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed. These requirements were not met:
RolesAuthorizationRequirement:User.IsInRole must be true for one of the following roles: (admin)
How it was reproduced
A minimal API made with dotnet new web -f net10.0 on SDK 11.0.100, with
Microsoft.AspNetCore.Authentication.JwtBearer 10.0.0 and a test-only
symmetric key, running on Microsoft.AspNetCore.App 10.0.15 in the
Development environment, built and started by a small script, start.ps1, which runs dotnet build -nologo -v q in the project folder and then bin\Debug\net10.0\FixLab.exe --urls http://127.0.0.1:15630. Tokens came from the app's own /token
endpoint (JsonWebTokenHandler, HS256) into PowerShell variables and were sent
with curl.exe. The 403 was captured twice, with and without the logging entry. FixLab, port 15630, the routes /token and
/reports, the policy name AdminOnly, the role
admin and the subject david.chen are the test's own.
Frequently asked
- What does 'RolesAuthorizationRequirement:User.IsInRole must be true for one of the following roles' mean?
- The user is authenticated but has none of the roles in brackets. In the test a valid token without a role claim logged this line and the endpoint answered 403.
- Why does ASP.NET Core return 403 and not 401 for a missing role?
- The token was accepted, so the user was known; only the role requirement failed. In the test the token without the role got 403, not 401, and the log named only the role requirement.
- How do I log why ASP.NET Core authorization failed?
- Add "Microsoft.AspNetCore.Authorization": "Information" under Logging:LogLevel in appsettings.json. With the template levels the test printed nothing for the 403.
More decoded errors in the Fixes category. For a request with no user at all the log names a different requirement: 'DenyAnonymousAuthorizationRequirement: Requires an authenticated user'.