ASP.NET Core Identity Deep Dive — Members
By: Soheil Alizadeh
Tags: Net Core, Identity, Microsoft, Aspnetcore, Authentication

In the previous blog we talked about nuget packages and today we want to study summary of asp.net core identity members.

In most of APIs that asp.net core identity prepares for us, there are some members of it so that they have hand in the APIs process. Therefore, here we have a list of asp.net core members with an explanation in this blog.

Members

Stores

Managers

Validators

IdentityOptions

IdentityErrorDescriber

Normalizer

UserClaimsPrincipalFactory

IdentityResult

Identity Models

IdentityBuilder

Default UI

Stores

Stores are lower-level classes or interfaces in the asp.net core identity system. they follow repository pattern in themselves. Stores in this system act as a data store and its default data store implemented by Entity Framework Core. we can change the asp.net core identity data store and use another like Dapper, MongoDB so that we aren’t dependent on using a specific data store.

If we look at asp.net core identity stores we will see common methods that most of them are CURD operation. here is some note that we should pay attention to them:

Entity Framework Core acts as a Store in ASP.NET Core Identity. Entity Framework Core is the default Store in ASP.NET Core Identity. Here is note that is EFCore data store supports by ASP.NET team and other data store supporting by the community.

Following list shows stores that are there in the asp.net core system:

As default there are some store implementation:

UserStoreBase( as default without data storage ), this is just for abstraction

RoleStoreBase( as default without data storage), this is just for abstraction

EF/UserStore: UserStoreBase ( in Microsoft.AspNetCore.Identity.EntityFrameworkCore)

EF/RoleStore: RoleStoreBase ( in Microsoft.AspNetCore.Identity.EntityFrameworkCore )

Don’t worry about TUser and TRole, we will talk about them in continue.

Managers

Managers are high-level classes in asp.net core identity system. they act as service in the system and they use data store internally to Implement CRUD operation and more methods for manage identity models. Also other members of asp.net core identity used here like IdentityOptions, Validators, Normalizer, IdentityErrorDescriber, etc.

In stores usage, managers just use interface of stores for DI and decoupling system’s data store, managers don’t use them directly.

The Following list shows managers that are there in the asp.net core system:

Please open these managers source code and look at their constructor and methods.

the graph for better understanding

Validators

Validators are for identity model validation. they have a ValidateAsync method that gets a manager and an identity model. we pass them to the ValidateAsync it returns an IdentityResult to showing the validation result.

IdentityOptions

IdentityOptions represents all the options we can use to configure the identity system. this options configure in startup (we will study them). the options that are there here are for Claims, User, Password, Lockout, Sign-in, Stores, etc.

its properties:

IdentityErrorDescriber

IdentityErrorDescriber is for asp.net core identity system error messages. in this class, there are methods that return IdentityError with a default message and code (the code is for the identity error message). you could localize this class for your main language. the managers use this class to returns an IdentityResult with messages.

Normalizer

This class is for normalizing a string value and it uses in managers. In some cases when we register a user in the system, the manager uses this for normalizing UserName and Email value and this is useful for searching or lookup.

UpperInvariantLookupNormalizer : ILookupNormalizer

UserClaimsPrincipalFactory

This class is for registering user claims as default. it uses mangers and IdentityOptions internally to configure specific claims. the claims like UserName, Roles, UserId gives to the user.

IdentityResult

IdentityResult used in most of asp.net core identity APIs store, manager and other members. this class contains two properties Succeeded, Errors that shows the executed operation status.

Identity Models

If you look at previous members you see TUser and TRole etc, they are identity models that asp.net core identity used them in the whole of the system. they consist of properties about Users and Roles. The TKey here is the type of primary key for the model that could specific that if you don’t pass any type it uses string. Also, there are other type models that you can see them in the following list:

These Models aren’t Entity Framework Models

or

These Models aren’t dependent with Entity Framework

IdentityBuilder

IdentityBuilder is for configuring identity services and with this class, you cloud change or add managers, stores, validators, etc. it used in startup class to configuring asp.net core identity.

Default UI

This is a default asp.net core web app that uses identity APIs to prepare a complete sample of asp.net core identity that has many features. this full sample is as a Razor Class Library and it could be a reusable UI. asp.net core identity as default use this UI and if you want custom UI or Implementation don’t use it.

We’ll study all of these members and learn how we can customize each of them.

Next POST