Search code examples
httpasp.net-coreclientstore

ASP.Net Core 2(.1.2) - Save user data without having to trust the client


I'm currently working with ASP.Net Core 2.1.2 and I can't find a solution for my problem.

Currently I'm building a controlpanel together with Angular 5. The data for a user is stored in a MySQL database. To have access to the controlpanel you have to login - and the server will load some data. Important is the admin-level (1-?) - some actions are only allowed for admins with atleast a level. For the authentication I'm using JWTBearer, which gets sent by the client at every HTTP action as header. But in some methods I also want to check the admin-level.

Now where can I store data for the client, like his admin-level? Is it safe to save it with a Claim? But then wouldn't it be possible for the client to modify it clientside and send a "custom" header? I also tried to put the data in a dictionary and use the (HttpContext.)User (of type ClaimsPrinciple) as the key, but that won't work because User is always different at every Request.

Is there any safe way to store the data for a User?


Solution

  • You can safely store your admin-level information in a Claim, unless you're worried that someone can read it. It's not possible to modify a Claim in JWT, because its value is signed by key which only you should know and after the modification this token will be invalid. Read this article to get more information about JWT