一步一步学习IdentityServer3 (7)
在介绍自定义用户服务之前先对IdentityServerServiceFactory说明下 Idr3的服务工厂
下面有很多idr3提供的接口服务,
如:ViewService、UserService、ClientStore 等很多,可以做很多的事情
其实它承载的不光是自身的接口服务,其实还提供了 服务注册 DI ,我们可以注册自己的接口服务实现
自定义用户服务只需要去实现 IUserService接口就行了
factory.UserService = new Registration<IUserService, IdrConfig.UserServices>();
去看下IUserService接口中的方法
//
// 摘要:
// This method gets called when the user uses an external identity provider to authenticate.
// The user's identity from the external provider is passed via the `externalUser`
// parameter which contains the provider identifier, the provider's identifier for
// the user, and the claims from the provider for the external user.
//
// 参数:
// context:
// The context.
Task AuthenticateExternalAsync(ExternalAuthenticationContext context);
//
// 摘要:
// This method gets called for local authentication (whenever the user uses the
// username and password dialog).
//
// 参数:
// context:
// The context.
Task AuthenticateLocalAsync(LocalAuthenticationContext context);
//
// 摘要:
// This method is called whenever claims about the user are requested (e.g. during
// token creation or via the userinfo endpoint)
//
// 参数:
// context:
// The context.
Task GetProfileDataAsync(ProfileDataRequestContext context);
//
// 摘要:
// This method gets called whenever identity server needs to determine if the user
// is valid or active (e.g. if the user's account has been deactivated since they
// logged in). (e.g. during token issuance or validation).
//
// 参数:
// context:
// The context.
Task IsActiveAsync(IsActiveContext context);
//
// 摘要:
// This method is called prior to the user being issued a login cookie for IdentityServer.
//
// 参数:
// context:
// The context.
Task PostAuthenticateAsync(PostAuthenticationContext context);
//
// 摘要:
// This method gets called before the login page is shown. This allows you to determine
// if the user should be authenticated by some out of band mechanism (e.g. client
// certificates or trusted headers).
//
// 参数:
// context:
// The context.
Task PreAuthenticateAsync(PreAuthenticationContext context);
//
// 摘要:
// This method gets called when the user signs out.
//
// 参数:
// context:
// The context.
Task SignOutAsync(SignOutContext context);
IUserService
我们在自己定义的 UserServices中去实现这些接口方法
OwinContext ctx;
//修改 这里依赖我们注册的接口服务
ILYMUser _userServices;
public UserServices(OwinEnvironmentService owinEnv,ILYMUser userServices) {
ctx = new OwinContext(owinEnv.Environment); _userServices=userServices;
}
到了这一步,其实只是去实现它的接口,在接口方法实现中我们要用自己的接口服务怎么办呢?
其实只需要在factory上注册自己的 服务接口就行了,然后在创建UserServices 构造函数是依赖我们之前注册的自定义服务接口就ok了
factory.Register(new Registration<ILYMUser, LYMUser>());
factory.UserService = new Registration<IUserService, IdrConfig.UserServices>();
这里的ILYMUser、LYMUser自定的接口服务,定义好登录相关方法,在UserServices中本地身份验证的中实现先关业务逻辑就ok
AuthenticateLocalAsync:当用户使用该方法时,该方法将调用本地身份验证 用户名和密码对话框
Tips:这里Owin中间件上下文对象需要创建idr3的环境变量,可以扩展提交一些其他授权参数
一步一步学习IdentityServer3 (7)的更多相关文章
- 一步一步学习IdentityServer3 (1)
学习之初: IdentityServer3我自己最开始了解到的就是做一个SSO单点登录,后面发现还有单独的认证服务功能,其实它还可以做APIs的访问控制,资源授权,另外还可以为提供第三方登录,其他的自 ...
- 一步一步学习IdentityServer3 (2)
下面就来做一个例子:IdentityServer3服务端的配置 VS2015创建一个MVC项目 IdrOAuth 用来授权的认证的站点
- 一步一步学习IdentityServer3 (4)
其实上述例子 很多都很找到 但是在实际生态环境中给例子有很多不一样的地方 比如自定已登录界面怎么做? 怎么访问自己的用户数据库实现登录? 怎么在接口中使用,在接口中又怎么实现与Idr3结合授权? 等等 ...
- 12.Linux软件安装 (一步一步学习大数据系列之 Linux)
1.如何上传安装包到服务器 有三种方式: 1.1使用图形化工具,如: filezilla 如何使用FileZilla上传和下载文件 1.2使用 sftp 工具: 在 windows下使用CRT 软件 ...
- (转) 一步一步学习ASP.NET 5 (四)- ASP.NET MVC 6四大特性
转发:微软MVP 卢建晖 的文章,希望对大家有帮助.原文:http://blog.csdn.net/kinfey/article/details/44459625 编者语 : 昨晚写好的文章居然csd ...
- (转) 一步一步学习ASP.NET 5 (二)- 通过命令行和sublime创建项目
转发:微软MVP 卢建晖 的文章,希望对大家有帮助. 注:昨天转发之后很多朋友指出了vNext的命名问题,原文作者已经做出了修改,后面的标题都适用 asp.net 5这个名称. 编者语 : 昨天发了第 ...
- 一步一步学习SignalR进行实时通信_1_简单介绍
一步一步学习SignalR进行实时通信\_1_简单介绍 SignalR 一步一步学习SignalR进行实时通信_1_简单介绍 前言 SignalR介绍 支持的平台 相关说明 OWIN 结束语 参考文献 ...
- 一步一步学习SignalR进行实时通信_8_案例2
原文:一步一步学习SignalR进行实时通信_8_案例2 一步一步学习SignalR进行实时通信\_8_案例2 SignalR 一步一步学习SignalR进行实时通信_8_案例2 前言 配置Hub 建 ...
- 一步一步学习SignalR进行实时通信_9_托管在非Web应用程序
原文:一步一步学习SignalR进行实时通信_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信\_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信_9_托管在非We ...
- 一步一步学习SignalR进行实时通信_7_非代理
原文:一步一步学习SignalR进行实时通信_7_非代理 一步一步学习SignalR进行实时通信\_7_非代理 SignalR 一步一步学习SignalR进行实时通信_7_非代理 前言 代理与非代理 ...
随机推荐
- 六、java异常处理
目录 一.异常的概念 二.异常的分类 三.异常的捕获和处理 四.使用自定义异常 一.异常的概念 java异常是指java提供的用于处理程序运行过程中错误的一种机制 所谓错误是指在程序运行的过程中发生的 ...
- tp5.1 高级查询之 表里2字段比较大小
$map = [ 'status' => 1, 'is_show' => 1,]; $result = Db::name('coupon') ->where($map) ->w ...
- https 协议信息查看
https://www.ssllabs.com/ssltest/」—————————
- Python【操作EXCEL文件】
#Python中,对EXCEL文件的读写操作需要安装.导入几个第三方模块#xlrd模块:只能读取EXCEL文件,不能进行写操作#xlwt模块:只能进行写操作,但是不能是覆盖写操作(也就是修改Excel ...
- Git2:Git基本操作
目录 一.git全局配置 二.创建一个版本库 三.git的常用操作 1.版本提交与回退 1.1.版本提交 1.2.版本回退 2.工作区.版本库与暂存区 2.1.工作区 2.2.版本库 3.管理文件的修 ...
- HDU 1686 Oulipo (KMP 可重叠)
题目链接 Problem Description The French author Georges Perec (1936–1982) once wrote a book, La dispariti ...
- 【译】第七篇 SQL Server代理作业活动监视器
本篇文章是SQL Server代理系列的第七篇,详细内容请参考原文 在这一系列的上一篇,你创建并配置SQL Server代理作业.每个作业有一个或多个步骤,可能包含大量的工作流.在这篇文章中,将查看作 ...
- windows 10 部署flask web
起因 本来想这用django 写一个web 应用程序,便于管理mongodb的数据.结果django 不直接支持mongodb……又没时间研究NoSQL.于是想着随便整个api吧…… 于是先用flas ...
- Multiple HTTPS Bindings IIS 7 Using appcmd
http://toastergremlin.com/?p=308 Sometimes when using a wildcard SSL or Unified Communications Certi ...
- NOIP 2016 迟来的满贯
17-03-22,雨 17-03-22,一个特别重要的日子 在这一天,本蒻攻克了NOIP 2016最难的一题,D1T2——天天爱跑步 实现了NOIP 2016的AK! YAYAYAYAYAYAY 自然 ...