© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
163 replies
Filomeon

✅ AuthorizationHandlerContext in ASP.NET API with Auth0

Hello 😅
I am trying to implement Auth0 in my ASP.NET API consumed by Angular app. It is a personal project.
For some reason that i can't find, I am not authorized to Update my Ingredient (Its an application to manage cooking recipes).
I tried to follow every guides from Auth0 to implement it right, and i really can't find where i did wrong.

Right now, if i call the API endpoint to update ingredient, it says I am Unauthorized (in the logs):
2023-09-24 02:40:18.414 +02:00 [INF] Authorization failed. These requirements were not met: Kitchen.Api.Tools.HasScopeRequirement

When i debug my API, and i arrive at the point of this code :
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
{
    protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
    {
        // If user does not have the scope claim, get out of here
        if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
            return Task.CompletedTask;
        ...
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
{
    protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
    {
        // If user does not have the scope claim, get out of here
        if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
            return Task.CompletedTask;
        ...

I see that my "context" has an error in Resource. It says in the debug window :
Session = '((Microsoft.AspNetCore.Http.DefaultHttpContext)context.Resource).Session' threw an exception of type 'System.InvalidOperationException'
Also this context has no claims, that's why it returns out of the method and says I am Unauthorized... I guess ?

I am trying to make a good auth for my app and i have no idea of where to look at to solve this problem.

Thank you for reading this, i hope someone will be able to give me some direction.
Peace ✌️
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ Auth0 and ASP.NET API
C#CC# / help
3y ago
❔ ASP.NET Core Web API with Auth0
C#CC# / help
3y ago
❔ CRUD API ASP.Net
C#CC# / help
3y ago
✅ Authorization in ASP.NET Web Api
C#CC# / help
2y ago