我是身份服务器的新手,并且有一个与Asp.net身份表不同的现有数据库,但是我看到了许多示例和视频教程,这些示例和视频教程使用asp.net身份进行登录。问题是我不想使用asp.net身份。如何将身份服务器用作单点登录?
services.AddIdentityServer(option => {
option.UserInteraction.LoginUrl = "/Accounts/Login";
})
.AddInMemoryApiResources(Constants.GetApis())
.AddInMemoryIdentityResources(Constants.GetIdentityResources())
.AddInMemoryClients(Constants.GetClients())
.AddDeveloperSigningCredential(persistKey: false);
您不需要摆脱asp.net身份。突出实现IUserStore,如下面的实现所示,您将使用自己的机制从现有数据库中获取数据。以下是实现IUserStore的一些示例
public async Task<Users> FindByIdAsync(string userId, CancellationToken cancellationToken)
{
//here you have to write the code to get data from existing db like ado.net or some third party api
}
在下面的方法中,您必须在现有数据库中为用户表创建poco类并将其传递。
public Task<string> GetUserIdAsync(Users user, CancellationToken cancellationToken)
{
return Task.FromResult(user.user_id.ToString());//user_id will be replaced by your user id column name
}
还添加您的User poco类,如下所示
var builder = services.AddIdentityServer()
.AddInMemoryIdentityResources(Config.GetIdentityResources())
//.AddInMemoryApiResources(Config.GetApis())
//.AddInMemoryClients(Config.GetClients())
.AddClientStore<ClientStore>()
.AddResourceStore<ResourceStore>()
.AddAspNetIdentity<Users>()//here
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句