I think itβs quite dangerous to let the client decrypt the token. If they can do this, an attacker can change the token and claims inside. If you do not check the validity of the claims (possibly because they are provided by a third party), this can lead to an escalation of privileges and compromise of your application.
If the client application requires requirements - perhaps for the layout of the user interface, you can provide them separately to the token. One way to do this is with ActionFilterAttribute , to write a complaint about a custom HTTP header. If claims are faked here, this only affects the client, since you will check the protected claims inside the token before processing any request.
public AddClaimsAttribute : System.Web.Http.Filters.ActionFilterAttribute { var principal = actionExecutedContext.ActionContext.RequestContext.Principal as ClaimsPrincipal; if (principal != null) { var claims = principal.Claims.Select(x => x.Type + ":" + x.Value).ToList(); actionExecutedContext.Response.Content.Headers.Add("Claims", String.Join(",", claims)); } }
Then your client should simply check this header and analyze it.
This is a basic example, you can format it as JSON or add a series of custom headers "IsAdmin", "IsEditingUser", etc.
Since this is a filter, you can apply it globally to every request, every action on the controller or a specific action as necessary.
source share