Skip to content

Instantly share code, notes, and snippets.

@OnSive
Last active February 9, 2021 16:05
Show Gist options
  • Select an option

  • Save OnSive/3a5b4bf314f8e3e1758213fd7b6bb134 to your computer and use it in GitHub Desktop.

Select an option

Save OnSive/3a5b4bf314f8e3e1758213fd7b6bb134 to your computer and use it in GitHub Desktop.
[GetUserAsync with IdentityServer Fix] Let you use the UserManager.GetUserAsync function again #Blazor #IdentityServer
/* Add following code to the server Startup.cs file */
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
// Add this configuration of the IdentityServer options
// https://github.com/dotnet/AspNetCore.Docs/issues/17517#issuecomment-605993247
services.Configure<IdentityOptions>(options => options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier);
}
// GetUserAsync works now within a controller
var user = await _userManager.GetUserAsync(User);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment