I was looking to use Windows Authentication for a Blazor Server app, but hit a small issue with the default Identity Name. i.e. when you used
<AuthorizeView>
Hi @context.User.Identity.Name
</AuthorizeView>
I got back 'Hi DOMAIN\A123456', which might be the AD object name, but its not what users would say their name was. I also noticed during debugging that the Identity had pulled back all of my AD groups, but not things like Given Name.
How can I override/amend/alter the processing to 'fix' this, ideally put a proper name in the Name claim and move the id into the NameIdentifier claim.
This is what I came up with using
IClaimsTransformation, but not sure if its the right approach at all, esp given that with just the out-of-the-box Blazor project this thing is called 7 times! If I added any db type logic to get the roles or name then this is going tank performance...Hopefully its reasonably clear what I've done, but basically ignore the principal from the built in Windows Auth and create your own. Also note that the
GenericIdentitydoes want aClaimTypes.Rolefor roles (for use in theAuthorizeViewcomponents), and not whatever type theWindowsIdentityneeded.I've subsequently realised that WindowsAuthentication isn't not going to work for my app, and I'll go back to custom auth that just uses AD to check their passwords via a standard pair of login boxes.