04. PART 2 IdentityServer4 ASP.NET Core Identity .NET Core 3.1
04. PART 2 IdentityServer4 ASP.NET Core Identity .NET Core 3.1
如果您已经来到这里,那么祝贺你的坚持,最难的部分已经完成了。我们仅仅需要的 ASP.NET Core Identity 创建数据库迁移,来创建数据库表。我将帮助你理解新的 identity 表。如同 IdentityServer4 的表一样。在后继的教程中,我们将开始为用户添加自定义的属性,来开始扩展功能。
Database code-first migration
In Visual Studio open Package Manager Console. First we need to add the migration for ASP.NET Core Identity database context (IdentityDbContext). Like so
在 Visual Studio 中打开包管理器控制台。我们首先需要添加用于 ASP.NET Core Identity 的数据库上下文 (IdentityDbContext) 迁移。如下所示:
Add-Migration InitialIdentityDbMigration -c IdentityDbContext -o Data/Migrations/AspNetIdentity/AspNetIdentityDb

This will add database migration “InitialIdentityDbMigration” to “Data/Migrations/AspNetIdentity” folder right next to the IdentityServer4 migrations for configuration and persisted grants. Let’s update the database structure with ASP.NET Core Identity tables. In Package Manager Console execute update database command like so
这将会在 Data/Migrations/AspNetIdentity 文件夹中添加名为 InitialIdentityDbMigration 的数据库迁移。相邻于配置和持久授权的 IdentityServer4 迁移。然后,使用 ASP.NET Core Identity 更新数据库表结构。在包管理控制台中执行更新数据库的命令,如下所示:
Update-Database -Context IdentityDbContext
That’s it! We previously successfully migrated all temporary in-memory configuration to the database, now we also migrated the user store. Wow. Take a moment and relax now. Moment gone. Let’s see new tables we got to play with.
PS. Feel free to delete the “ScaffoldingReadme.txt” file from the project root. This readme file was automatically added when we did the ASP.NET Core Identity scaffolding.
好啦!上一次,我们成功地将临时保留在内存中的配置迁移到数据库中,现在,我们也迁移来用户存储。天哪。现在可以休息一下啦。好啦,现在可以看一下将要使用的表了。
PS:现在可以删除项目根目录中的
ScaffoldingReadme.txt文件。该文件是在我们架构 ASP.NET Core Identity 的时候自动被添加进来的。
ASP.NET Core Identity tables
I used the MSSQL database in this example but it’s pretty much the same for PostgreSQL. Here is the list of tables that we have in the “IdentityServerQuickstart” database. Seven tables that start with the “AspNet” prefix are the ASP.NET Core Identity tables that hold user store (users, claims, roles, logins, and user tokens).
在该示例中,我使用的是 MSSQL 数据库,但是对于 PostgreSQL 来说及其类似。下面是 IdentityServerQuickstart 数据库中数据表的列表。7 张以 AspNet 为前缀的表是 ASP.NET Core Identity 表,用来持有用户存储 (users, claims, roles, logins 以及用户的令牌)

Let’s see the relationship between ASP.NET Core Identity tables in a diagram
下图中是 ASP.NET Core Identity 表之间的关系。

- “dbo.AspNetRoleClaims” 保存赋予特定角色的声明.
- “dbo.AspNetRoles” 角色表。保存所有可以赋予用户的角色
- “dbo.AspNetUserClaims” 用户的声明。声明与角色不同,声明就是一个键值对。你可以有角色或者没有。声明为特定的声明提供值,从另一个角度看,可以看作赋予用户的可选的属性。
- “dbo.AspNetUserLogins” 该表连接外部用户到本地用户。table is connecting external users to local users. All users specified in
- “dbo.AspNetUsers” table are local users. Say you want to login with Google and you want to link your Google account with your local account. This table holds that link so once you are linked you don’t have to go through the linking process again.
- “dbo.AspNetUserRoles” table is a many-to-many relationship table that connects users with assigned roles.
“dbo.AspNetUsers” table is holding users. All of the user properties like username, email, password are stored here. We can also add custom user properties here to extend the user. - “dbo.AspNetUserTokens” table is holding external authentication tokens. This table is also used for keeping TOTP authenticator keys and recovery codes for user.
Recap
We added migration for ASP.NET Core Identity, updated the database with new tables and learned about each table. I explained the rest of the tables (the non “AspNet” prefix tables) in my previous tutorial.
In my next tutorial we will start adding custom attributes to the user. “Hard” stuff is pretty much over, we are now off to customization and adding new features.
You can find the project here.
我们添加了针对 ASP.NET Core Identity 的迁移,使用新的表更新了数据库,学习了每张表的用途。其他非 AspNet 前缀的表在前面的教程中已经做过介绍了。
在下一教程中,我们将开始为用户添加自定义的属性。困难的工作已经过去了,我们现在可以定制并添加新的功能了。
04. PART 2 IdentityServer4 ASP.NET Core Identity .NET Core 3.1的更多相关文章
- IdentityServer4 中文文档 -14- (快速入门)使用 ASP.NET Core Identity
IdentityServer4 中文文档 -14- (快速入门)使用 ASP.NET Core Identity 原文:http://docs.identityserver.io/en/release ...
- IdentityServer4【QuickStart】之使用asp.net core Identity
使用asp.net core Identity IdentityServer灵活的设计中有一部分是可以将你的用户和他们的数据保存到数据库中的.如果你以一个新的用户数据库开始,那么,asp.net co ...
- IdentityServer(12)- 使用 ASP.NET Core Identity
IdentityServer具有非常好的扩展性,其中用户及其数据(包括密码)部分你可以使用任何想要的数据库进行持久化. 如果需要一个新的用户数据库,那么ASP.NET Core Identity是你的 ...
- .net core Identity集成IdentityServer4 (1)基本操作
一. 新建asp.net core identity项目 新建项目->asp.net core web应用程序-> web应用程序(模型视图控制器)&更改身份验证为个人. 新建一个 ...
- ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程
原文:ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core Identity 迁移数据 上一章节中我们配置了 ...
- 从零搭建一个IdentityServer——集成Asp.net core Identity
前面的文章使用Asp.net core 5.0以及IdentityServer4搭建了一个基础的验证服务器,并实现了基于客户端证书的Oauth2.0授权流程,以及通过access token访问被保护 ...
- IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习保护API
IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习之保护API. 使用IdentityServer4 来实现使用客户端凭据保护ASP.N ...
- ASP.NET Core Identity Hands On(1)——Identity 初次体验
ASP.NET Core Identity是用于构建ASP.NET Core Web应用程序的成员资格系统,包括成员资格.登录和用户数据存储 这是来自于 ASP.NET Core Identity 仓 ...
- ASP.NET Core Identity Hands On(2)——注册、登录、Claim
上一篇文章(ASP.NET Core Identity Hands On(1)--Identity 初次体验)中,我们初识了Identity,并且详细分析了AspNetUsers用户存储表,这篇我们将 ...
- ASP.NET Core Identity 实战(2)——注册、登录、Claim
上一篇文章(ASP.NET Core Identity Hands On(1)--Identity 初次体验)中,我们初识了Identity,并且详细分析了AspNetUsers用户存储表,这篇我们将 ...
随机推荐
- 前端使用 Konva 实现可视化设计器(23)- 绘制曲线、属性面板
本章分享一下如何使用 Konva 绘制基础图形:曲线,以及属性面板的基本实现思路,希望大家继续关注和支持哈(多求 5 个 Stars 谢谢)! 请大家动动小手,给我一个免费的 Star 吧~ 大家如果 ...
- 2.3.1 ChatGLM3简介与安装
安装:pip install modelscope pip install torch==2.0.1 torchaudio torchvision -i https://pypi.tuna.tsing ...
- 左值 <->右值
左值引用指向左值 右值引用指向右值 int a = 5; int &ref_a = a; // 左值引用指向左值,编译通过 int &ref_a = 5; // 左值引用指向了右值,会 ...
- C # 的 IsNullOrEmpty
作用:判断字符串是否是 null 或者 "" 如果是 null or "" 就返回 true IsNullOrEmpty是判断字符串的Null值和"& ...
- 函数计算平台 OpenFunction 在自动驾驶领域的应用
嘉宾 | 霍秉杰 整理 | 王新 出品 | CSDN 云原生 2022 年 5 月 10 日,在 CSDN 云原生系列在线峰会第 4 期"ApacheSkyWalking 峰会"上 ...
- Runtime类的简单应用
1.描述 Runtime:描述运行时状态. 在整个JVM中,Runtime类是唯一一个与JVM运行状态有关的类,且默认提供一个该类的实例化对象. 由于在每一个JVM进程中只允许提供一个Runtime类 ...
- 0基础读顶会论文—Kappa:一种用于无服务器计算的编程框架
原文链接 代码:快速使用kappa 首先的首先,可以先去了解一下lambda架构 Abstract 在本文中提出了Kappa,一个简化无服务器开发的框架.它使用检查点来处理lambda函数超时,并提供 ...
- Wgpu图文详解(02)渲染管线与着色器
在本系列的第一篇文章中(<Wgpu图文详解(01)窗口与基本渲染>),我们介绍了如何基于0.30+版本的winit搭建Wgpu的桌面环境,同时也讲解了关于Wgpu一些基本的概念.模块以及架 ...
- 无法访问k8s.gcr.io下载镜像问题解决办法
部署K8S最大的难题是镜像下载,在国内无FQ环境情况下很难从k8s.gcr.io等镜像源里下载镜像. 这种情况下正确做法是: 直接指定国内镜像代理仓库(如阿里云代理仓库)进行镜像拉取下载. 成功拉取代 ...
- manim边学边做--立方体和棱柱体
本篇介绍Manim中创建三维立体的两个常用对象:Cube和Prism. Cube在制作动画时,可以用于展示立体几何中的立方体概念,或者通过旋转.缩放等动画效果来帮助理解三维空间中的几何变换. Pris ...