在介绍自定义用户服务之前先对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. HDU 6231

    K-th Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Tot ...

  2. 「Vue」自定义按键修饰符

    vue.config.keyCodes.f2 = 113 设置完成后就可以绑定f2的按键操作@keyup.f2="add" 自带的有enter esc delete 空格 上下左右 ...

  3. P2776 [SDOI2007]小组队列

    P2776 [SDOI2007]小组队列 题目背景 嘛,这道非常简单的给大家提供信心的省选题洛谷居然没有! 这么简单的题怎么可以没有! 给大家提升士气是义不容辞的责任! 所以我就来补一下啦.. 值得一 ...

  4. [LeetCode] 382. Linked List Random Node ☆☆☆

    Given a singly linked list, return a random node's value from the linked list. Each node must have t ...

  5. matlab中uigetfile命令的应用

    matlab中uigetfile命令的应用 uigetfile命令的应用 此函数的用法为 [FileName,PathName,FilterIndex] = uigetfile(FilterSpec, ...

  6. [问题]通过IIS宿主发布WCF服务,客户端添加服务引用出错的解决办法

    环境配置:Web服务器:Windows Server 2008,iis7.5,.net4.0客户端:XPsp3 vs2010 sp1 问题描述:1.确定WCF服务访问地址  http://servic ...

  7. 基本控件文档-UISegment属性

    CHENYILONG Blog 基本控件文档-UISegment属性 Fullscreen   UISegment属性技术博客http://www.cnblogs.com/ChenYilong/ 新浪 ...

  8. InnoDB 引擎独立表空间

    InnoDB 引擎独立表空间   使用过MySQL的同学,刚开始接触最多的莫过于MyISAM表引擎了,这种引擎的数据库会分别创建三个文件:表结构.表索引.表数据空间.我们可以将某个数据库目录直接迁移到 ...

  9. celery简介

    目录 Celery简介 Celery架构 中间件选择 Celery序列化 简单项目 Celery简介 celery userguide 知乎大神解释celery Celery(芹菜)是基于Python ...

  10. const与指针

    C++中const与指针 1.常指针: ; int * const pInt = &x; 其中PInt是常指针,pInt的值无法改变,但其指向的内容可以改变. 2.指向常量的指针 有两种写法: ...