Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Adding a display claim

$
0
0

I want to grab a users real name and be able to use it anywhere without repeatedly querying AD. Claims looks like the best way to do this.

My original authorization worked and was done using policy:

services.AddAuthorization(options =>
{
options.AddPolicy("Admin", policy =>
policy.Requirements.Add(new GetGroup(new string [] { "Admin"})));
options.AddPolicy("User", policy =>
policy.Requirements.Add(new GetGroup(new string [] { "User"})));
});

I found a post suggesting the below should work to add claims (in startup.cs):

app.UseAuthentication();

app.Use(async (context, next) => {

if (context.User != null&& context.User.Identity.IsAuthenticated)

   {

        context.User.Claims.Append(new Claim("DName", GetDName())));

    }   

     await next();

});

I don't get an error, but it doesn't seem to append the claim. What else do I need to do?

I want to be able to use 'User.Claims.First(c => c.Type == "DName").Value'


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>