title: Blazor authentication role based
body: <p>I'm working on a client-side blazor application with the last webassembly version (3.2.0).</p>
  
  <p>I started the project from the visual tool with enabling local authentications and I tried to add roles. </p>
  
  <p>First, I added the roles in the ApplicationDbContext :</p>
  
  <pre><code>public class ApplicationDbContext : ApiAuthorizationDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext(
          DbContextOptions options,
          IOptions&lt;OperationalStoreOptions&gt; operationalStoreOptions) : base(options, operationalStoreOptions)
      {
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
  
          builder.Entity&lt;IdentityRole&gt;()
                 .HasData(new IdentityRole { Name = "User", NormalizedName = "USER", Id = Guid.NewGuid().ToString(), ConcurrencyStamp = Guid.NewGuid().ToString() });
          builder.Entity&lt;IdentityRole&gt;()
                 .HasData(new IdentityRole { Name = "Admin", NormalizedName = "ADMIN", Id = Guid.NewGuid().ToString(), ConcurrencyStamp = Guid.NewGuid().ToString() });
      }
  }
  </code></pre>
  
  <p>Then I added Roles to the IdentityBuilder in the startup class : </p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
     services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
         options.UseSqlServer(
             Configuration.GetConnectionString("DefaultConnection")));
  
     services.AddDefaultIdentity&lt;ApplicationUser&gt;(options =&gt; options.SignIn.RequireConfirmedAccount = true)
         .AddRoles&lt;IdentityRole&gt;()
         .AddEntityFrameworkStores&lt;ApplicationDbContext&gt;();
  
     services.AddIdentityServer()
         .AddApiAuthorization&lt;ApplicationUser, ApplicationDbContext&gt;();
  
     services.AddAuthentication()
         .AddIdentityServerJwt();
  
     services.AddControllersWithViews();
     services.AddRazorPages();
  }
  </code></pre>
  
  <p>And then in my DbInitializer I created an Admin account with both roles :</p>
  
  <pre><code>    private async Task SeedASPIdentityCoreAsync()
      {
          if (!await context.Users.AnyAsync())
          {
              var admin = new ApplicationUser()
              {
                  UserName = "admin@admin.com",
                  Email = "admin@admin.com",
                  EmailConfirmed = true,
              };
              var result = await userManager.CreateAsync(admin, "aA&amp;123");
              if (!result.Succeeded)
              {
                  throw new Exception(result.Errors.First().Description);
              }
  
              result = await userManager.AddClaimsAsync(admin, new Claim[]
                  {
                      new Claim(JwtClaimTypes.Email, "admin@admin.com"),
                      new Claim(JwtClaimTypes.Name, "admin@admin.com")
                  });
  
  
              ApplicationUser user = await userManager.FindByNameAsync("admin@admin.com");
  
              try
              {
                  result = await userManager.AddToRoleAsync(user, "User");
                  result = await userManager.AddToRoleAsync(user, "Admin");
              }
              catch
              {
                  await userManager.DeleteAsync(user);
                  throw;
              }
  
              if (!result.Succeeded)
              {
                  await userManager.DeleteAsync(user);
                  throw new Exception(result.Errors.First().Description);
              }
          }
      }
  </code></pre>
  
  <p>But the roles doen't appear in the JWT, and the client-side has no idea about the roles.</p>
  
  <p>How can I add the roles in the JWT, as with the new version of blazor, there is no need of the LoginController ? (If i well understood the changes)</p>