0

I'm learning aspnet.core and following tutorial related to IdentityServer4 for the Oauth2 server for the client app, in this case its react app.

After following the tutorial, I realise that all my tables has prefix AspNet: enter image description here

In IdentityServer4 docs though, I can see that they created tables with different prefix for different clients (API, Client). I've been trying to read the docs, search for the scaffolded templates that I got from:

dotnet new react -o <output_directory_name> -au Individual

But I can't find it anywhere. I even looked at the IdentityUser class in the context from namespace using Microsoft.AspNetCore.Identity;, and they have the table names without the prefix AspNet.

I'm coming from laravel, thus basically i have almost zero experience in c# and aspnet core. Can anyone help me explain?

Thanks

Robert Tirta
  • 2,593
  • 3
  • 18
  • 37
  • Not to be rude but really, start with a Hello World code set, understand it fully and then move to more complex examples. – Mark Schultheiss Aug 22 '20 at 15:26
  • I did. I followed tutorial for API, then I followed tutorial for ef core for a while until I needed authentication so I followed tutorial for auth in SPA. This question is related to the tutorial actually so... – Robert Tirta Aug 22 '20 at 15:30
  • I also read this question https://stackoverflow.com/questions/51483885/change-identityserver4-entity-framework-table-names# , but I can’t find the table edited on ‘Startup.cs’. I just want to know how did the template do it. Did i miss anything here? – Robert Tirta Aug 22 '20 at 15:40
  • 1
    I think that answer (key part) is the `services.AddIdentityServer() .AddConfigurationStore(options => {` and the code in that `.Invoke(o, new object[] { $"idn_{tableName}" });` - basically you need to add that service if you use that example. Seek to fully understand all the parts of the `Startup.cs` class and how they work together. Once I got that understanding, it made .Net core in this context much easier to comprehend – Mark Schultheiss Aug 22 '20 at 15:56

1 Answers1

1

Don't get confused with Microsoft.Identity and IdentityServer4. The tables that you are seeing with the prefix 'AspNet' from Microsoft Identity.

You can customize the way you want using the 'OnModelCreating' method of your DbContext. The below link has complete information on what you can do with Microsoft Identity. Identity model customization in ASP.NET Core

For Eg. below is some sample code from the above link to customize the table names

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);

    modelBuilder.Entity<IdentityUser>(b =>
    {
        b.ToTable("MyUsers");
    });

    modelBuilder.Entity<IdentityUserClaim<string>>(b =>
    {
        b.ToTable("MyUserClaims");
    });

    modelBuilder.Entity<IdentityUserLogin<string>>(b =>
    {
        b.ToTable("MyUserLogins");
    });

    modelBuilder.Entity<IdentityUserToken<string>>(b =>
    {
        b.ToTable("MyUserTokens");
    });

    modelBuilder.Entity<IdentityRole>(b =>
    {
        b.ToTable("MyRoles");
    });

    modelBuilder.Entity<IdentityRoleClaim<string>>(b =>
    {
        b.ToTable("MyRoleClaims");
    });

    modelBuilder.Entity<IdentityUserRole<string>>(b =>
    {
        b.ToTable("MyUserRoles");
    });
}
Thangadurai
  • 2,573
  • 26
  • 32
  • Whoa you’re a champ! So basically microsoft.identity is just a context class to customise the identityserver right? – Robert Tirta Aug 22 '20 at 22:52
  • May be for understanding, you can assume that the IdentityServer implementation is an extension of Microsoft Identity. – Thangadurai Aug 23 '20 at 05:18