在介绍自定义用户服务之前先对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)的更多相关文章

  1. 一步一步学习IdentityServer3 (1)

    学习之初: IdentityServer3我自己最开始了解到的就是做一个SSO单点登录,后面发现还有单独的认证服务功能,其实它还可以做APIs的访问控制,资源授权,另外还可以为提供第三方登录,其他的自 ...

  2. 一步一步学习IdentityServer3 (2)

    下面就来做一个例子:IdentityServer3服务端的配置 VS2015创建一个MVC项目 IdrOAuth 用来授权的认证的站点

  3. 一步一步学习IdentityServer3 (4)

    其实上述例子 很多都很找到 但是在实际生态环境中给例子有很多不一样的地方 比如自定已登录界面怎么做? 怎么访问自己的用户数据库实现登录? 怎么在接口中使用,在接口中又怎么实现与Idr3结合授权? 等等 ...

  4. 12.Linux软件安装 (一步一步学习大数据系列之 Linux)

    1.如何上传安装包到服务器 有三种方式: 1.1使用图形化工具,如: filezilla 如何使用FileZilla上传和下载文件 1.2使用 sftp 工具: 在 windows下使用CRT 软件 ...

  5. (转) 一步一步学习ASP.NET 5 (四)- ASP.NET MVC 6四大特性

    转发:微软MVP 卢建晖 的文章,希望对大家有帮助.原文:http://blog.csdn.net/kinfey/article/details/44459625 编者语 : 昨晚写好的文章居然csd ...

  6. (转) 一步一步学习ASP.NET 5 (二)- 通过命令行和sublime创建项目

    转发:微软MVP 卢建晖 的文章,希望对大家有帮助. 注:昨天转发之后很多朋友指出了vNext的命名问题,原文作者已经做出了修改,后面的标题都适用 asp.net 5这个名称. 编者语 : 昨天发了第 ...

  7. 一步一步学习SignalR进行实时通信_1_简单介绍

    一步一步学习SignalR进行实时通信\_1_简单介绍 SignalR 一步一步学习SignalR进行实时通信_1_简单介绍 前言 SignalR介绍 支持的平台 相关说明 OWIN 结束语 参考文献 ...

  8. 一步一步学习SignalR进行实时通信_8_案例2

    原文:一步一步学习SignalR进行实时通信_8_案例2 一步一步学习SignalR进行实时通信\_8_案例2 SignalR 一步一步学习SignalR进行实时通信_8_案例2 前言 配置Hub 建 ...

  9. 一步一步学习SignalR进行实时通信_9_托管在非Web应用程序

    原文:一步一步学习SignalR进行实时通信_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信\_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信_9_托管在非We ...

  10. 一步一步学习SignalR进行实时通信_7_非代理

    原文:一步一步学习SignalR进行实时通信_7_非代理 一步一步学习SignalR进行实时通信\_7_非代理 SignalR 一步一步学习SignalR进行实时通信_7_非代理 前言 代理与非代理 ...

随机推荐

  1. 一些程序OEP入口特征

    声明: 1.本文中使用的例子来源于吾爱破解的官方教程第一课中的无壳例子,本人利用空闲时间挨个进行查看并截图纪录下来 2.欢迎补充讨论 一些程序OEP入口特征 一.       AMS程序 1.载入PE ...

  2. 利用Snapshot快速跨Region迁移服务器

    当你需要对现有的网站进行跨区域迁移,或者是部署DR Site的时候,又不希望重新部署应用,有什么好办法呢?其实你可以利用Azure的磁盘snapshot进行磁盘级的复制,这样可以减少很多部署应用的时间 ...

  3. 在Ubuntu16.04上安装virtualbox后无法装载vboxdrv模块

    首先按照:http://blog.csdn.net/ipsecvpn/article/details/52175279 这个网址上的教程安装, 安装完成后报错:大体意思就是vboxdrv没有被内核装载 ...

  4. python---基础知识回顾(六)网络编程

    python---基础知识回顾(十)进程和线程(进程) python---基础知识回顾(十)进程和线程(多线程) python---基础知识回顾(十)进程和线程(自定义线程池) 一:Socket (一 ...

  5. COGS 1516. 棋盘上的车

    COGS 1516. 棋盘上的车 http://www.cogs.pro/cogs/problem/problem.php?pid=1516 ☆   输入文件:rook.in   输出文件:rook. ...

  6. C++的一些不错开源框架,可以学习和借鉴

    from https://www.cnblogs.com/charlesblc/p/5703557.html [本文系外部转贴,原文地址:http://coolshell.info/c/c++/201 ...

  7. WCF: Retry when service is in fault state.

    Service Host: using System; using System.Configuration; using System.ServiceModel; using System.Serv ...

  8. [整理]C语言中的static静态对象

    1.说明外部对象(静态外部变量和静态函数)    (1)static 用于说明外部变量或函数,使该对象的作用域限定为被编译原文件的剩余部分,即从对象说明开始到所在源文件的结束部分:    (2)被st ...

  9. C++传递二维数字给一个自定义函数

    如果参数是多维数组,那么参数必须指明第一维意外得所有未得长度:比如你的 void tt(char a[][20])或者 void tt(char (*a)[20]) 另外这样也是可以的char *a[ ...

  10. C语言实现线性表

    #include <stdio.h> #include <stdlib.h> //提供malloc()原型 /* 线性表需要的方法: 1. List MakeEmpty():初 ...