一步一步学习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_非代理 前言 代理与非代理 ...
随机推荐
- STM32 ------ HardFault_Hander 中断函数
1.数组越界(对数组赋值) 正常情况,数组越界会进入 HardFault_Hander 中断函数的无线循环. 避免数组越界的一个方法是:每次使用数组前,检查要放入数据的数据长度是否大于数组长度,大于则 ...
- 【Asp.net入门09】第一个ASP.NET 应用程序-处理窗体(1)
我们创建了一个HTML窗体,可以通过它显示受邀参加晚会的嘉宾,但是,当嘉宾单击Submit RSVP按钮时,同一个页面会反复多次显示.为了解决此问题,需要实现一段代码,用于在将窗体数据发布到服务器时执 ...
- Hadoop基础-HDFS分布式文件系统的存储
Hadoop基础-HDFS分布式文件系统的存储 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HDFS数据块 1>.磁盘中的数据块 每个磁盘都有默认的数据块大小,这个磁盘 ...
- Spring MVC原理介绍
1.Spring Web MVC是什么 spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解 ...
- bzoj千题计划124:bzoj1036: [ZJOI2008]树的统计Count
http://www.lydsy.com/JudgeOnline/problem.php?id=1036 树链剖分板子题 #include<cstdio> #include<iost ...
- codevs 3369 膜拜(线型)
3369 膜拜 http://codevs.cn/problem/3369/ 题目描述 Description 神牛有很多…当然…每个同学都有自己衷心膜拜的神牛.某学校有两位神牛,神牛甲和神牛乙.新入 ...
- soj1010. Zipper
1010. Zipper Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Given three strings, yo ...
- 列表函数&方法
列表(list)的基本操作,方法及属性.
- MongoDB警告信息
更多内容推荐微信公众号,欢迎关注: MongoDB警告信息: 1. WARNING: Using the XFS filesystem is strongly recommended with the ...
- post请求远程url 报错“基础连接已经关闭...Authentication.AuthenticationException...远程证书无效”解决方案
当我们有时用代码编写post请求url远程地址会报“基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系. ---> System.Security.Authentication.A ...