如何从现有数据库中为IdentityServer4获取用户 [英] How to get users from a existing database for identityServer4
问题描述
我尝试了解如何将存储在现有数据库(位于:localhost:3306)中的用户(电子邮件,密码,名字,姓氏和操作系统)绑定到我的identityserver4项目中,以便我可以使用这些信息来登录用户或将新用户注册到该数据库?
i try to understand how i can bind users (email, password, firstname, lastname and os on) which are stored in an existing database (located: localhost:3306) into my identityserver4 project so that i can use these information to login a user or register a new user into that database?
我阅读了一些教程(特别是 http://docs.identityserver.io/zh/release/quickstarts/8_entity_framework.html ),但我认为这始终适用于同一项目中的db.我的数据库不在同一个项目中.
I read some tutorials (specially http://docs.identityserver.io/en/release/quickstarts/8_entity_framework.html) but i think this is always for db in the same project. my db isn´t in the same project.
在这种情况下,我阅读了有关asp.net-core身份的信息.但我不完全了解那是怎么回事.
In this context i read about asp.net-core Identity. but i don´t understand completely how that´s related.
有人可以告诉我如何在我的项目中绑定数据库,以及身份与应用程序User的作用是什么?
Can someone tell me how can i bind a db in my project and what´s the role of identity with application User and so on?
预先感谢
推荐答案
本文与您的情况更为相关.您链接的链接用于配置数据,而不用于用户数据: http://docs.identityserver.io/en/release/quickstarts/6_aspnet_identity.html
This article is more relevant to your situation. The one you linked is for configuration data and not for user data: http://docs.identityserver.io/en/release/quickstarts/6_aspnet_identity.html
简而言之,您想通过Asp.Net Core Identity访问您的用户数据.您需要:
In short, you want to access your user data through Asp.Net Core Identity. You need to:
- 将包含相关字段的用户类作为数据库
- 创建EntityFramework DbContext类以将数据库映射到您的类
- 使用aspnet核心身份注册您的用户类和dbcontext
- 告诉IdentityServer使用AspNetIdentity
这是实现后的Startup ConfigureServices方法的外观.这里没有显示您需要创建的DbContext和User类.
This is what your Startup ConfigureServices method might look like once implemented. Not pictured here is the DbContext and User classes you need to make.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<YourUserStoreDbContextHere>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<YourUserClassHere, YourRoleClassHereIfAny>()
.AddEntityFrameworkStores<YourUserStoreDbContextHere>()
.AddDefaultTokenProviders();
services.AddIdentityServer()
// Other config here
.AddAspNetIdentity<YourUserClassHere>();
}
有关配置用户类和dbcontext的详细信息,请参阅AspNet Identity上的文档: https://docs.microsoft.com/zh-cn/aspnet/core/security/authentication/identity
Refer to the docs on AspNet Identity for details on configuring your user class and dbcontext: https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity
这篇关于如何从现有数据库中为IdentityServer4获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!