How many claims can a Role/User have in ASP.Net.Core.Identity?

djack109

How many claims can a role or user have? I've been working on an app using ASP.Net.Core 2.2 and AspNet.Core.Identity. All works fine until testing on my browser. Under debugging in VS2019 there is no such problem.

I deployed my app for further testing and run into this error (below). I have the same problem in IE, GC and FF.

HTTP Error 400. The size of the request headers is too long.

I'm using Roles and RoleClaims

After some digging around I find its to do with Role/Claims in the fact there are too many of them that it blows the cache. Basically Identity in trying to store all the claims in a cookie and the cookie is now just too big.

It just seems really odd that Microsoft would give you all that complexity only to have yo thwarted by the browser.

So my questions are: - What's the point of roles/claims if you can' exploit them because of browser restrictions? - It's there anything documented on the imaginary limit (max no. of claims per role)?

djack109

Just to let you know I could not get ITicketStore to work no matter what I tried. I even spent several days reading all the documents I could find on ITicketStore, it's not very well documented at all. And this seems like quite a common problem (the cookie thing and ITicketStore documentation).

Anyway, I changed my application so that Asp.Net.Identity only picks up the user role. This solves the cookie size problem.

I've implemented my own functions to check the role-claims. Which works better I feel as any changes happen live so no need to log on/off to get new claims or revoke existing claims.

I have a service function, that takes an IdentityUser<AppUser> and a Claim name (string).

_adminService.UserHasClaim(user, ClaimName) // returns true or false if you have that claim or not

I have my own table, identical to the AspNetRoleClaims table that contains the values. The Asp.Net.Identity version of that table is now empty so the cookie doesn't contain any claims.

    public bool UserHasClaim(AppUser user, string claimValue)
    {
        var claim = (from c in _context.AppUserRoleClaims
                     join t in _context.AppUserClaimTypes on c.ClaimID equals t.ID
                     join r in _context.UserRoles on c.RoleId equals r.RoleId
                     where r.UserId == user.Id && t.ClaimValue == claimValue select c).FirstOrDefault();

        return (claim != null);
    }

It might not be perfect or ideal but it works and I can't afford any more time trying to solve this using identity. I don't claim it to be ideal and I'll probably come back to it later in time.

Happy to take comments on a better workable solution, but for now that's how I've solved the problem.

So, moving on ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to separate large cookies in Asp.Net Identity into a smaller ones to allow MANY claims?

How can I have multiple Identity user types when using ASP.NET Core Identity and Entity Framework Core?

How to get user claims after signin through SignInManager in ASP .NET CORE Identity?

Dynamic claims asp.net core identity no DB persistence

ASP .NET CORE 2.2 JWT & Claims identity Authentication for Website

How to update claims in ASP.NET Core

What is the claims in ASP .NET Identity

How to get max value of claims value in ASP.NET Identity?

client specific claims identity server4 using asp.net core identity

How to make a middleware that can call database to check user claims to authorize a user in asp.net core 2.2

Claims Identity .NET CORE 3.0 API JWT

ASP.NET Identity Role claims missing

Identity Claims Provider Mapping in ASP.NET

how to get claims of another user using ASP.NET Core

asp.net core how to add claims to User

How to check privileges in JWT using Claims in ASP.NET Core?

How to invalidate and revalidate custom claims in ASP.NET Core?

How do I update user claims in Asp.net Core

asp.net core identity claims vs properties (efficiency point of view)

Role Claims in ASP.NET Core Identity compared to Role Permissions in custom auth

Adding Claims to an ASP.Net Identity Core user fails with EF insert error

Adding and accessing claims in asp net core 3.0 using built in Identity server

ASP.NET Identity Core - too many role related queries

Check claims (email) before creating a new cookie, without asp. core identity store using asp net core social login

How can I change default ASP.NET Identity table names in .NET CORE?

How to have many optional routes in .Net Core

Not able to get user group claims when using Azure AD as external login alongside Identity Core(ASP.NET Core 2.1)

Problem with Claims in ASP.NET Core (user still have some claim after updating database)

Claims based authorization in ASP.NET Core