IdentityServer4 sign-in
Sign-in
IdentityServer 代表 user 分配token之前,user必须登录IdentityServer
Cookie authentication
使用 cookie 进行身份认证的方式,是通过 Asp.Net Core 的 cookie authentication handler 实现的。
IdentityServer 注册了两个 cockie handler(一个用来身份认证中的session,另外用于一个temporary external cookie)。两者是默认配置使用的,可以通过 IdentityServerConstants类获得他们的名称(DefaultCookieAuthenticationScheme 和 ExternalCookieAuthenticationScheme)
以上的cookie只提供一个基本的配置(过期时间和 sliding),也可以通过注册自己的cookie handler来控制更多的内容。当使用ASP.NET Core中的AddAuthentication时,IdentityServer使用与AuthenticationOptions上配置的DefaultAuthenticateScheme匹配的cookie处理程序。
重写 cookie handler configuration
ConfigureService 时,在DI中注入 IdentityServer (通过AddIdentityServer)之后,再天剑自定义的 cookie authentication handler
services.AddIdentityServer()
.AddInMemoryClients(Clients.Get())
.AddInMemoryIdentityResources(Resources.GetIdentityResources())
.AddInMemoryApiResources(Resources.GetApiResources())
.AddDeveloperSigningCredential()
.AddTestUsers(TestUsers.Users);
services.AddAuthentication("MyCookie")
.AddCookie("MyCookie", options =>
{
options.ExpireTimeSpan = ...;
});
NOTE IdentityServer 内部会调用
AddAuthentication和AddCookie方法,并使用IdentityServerConstants.DefaultCookieAuthenticationScheme的自定义 Scheme,所以需要在调用AddIdentityServer之后再去调用这两个方法进行覆盖重写。
用户登录接口和身份认证管理系统
IdentityServer 没有提供 user 身份认证的用户界面或者用户数据库。自行开发。
Login 的流程

NOTE open-redirect attack,确保 returnUrl 是合法的, 参考 interaction service
Login Context
在 interaction service 调用 GetAuthorizationContextAsync 可以在登录页面获取到request的上下文信息(比如:client, 提示参数, idP(identity provider) 提示等等),以便于自定义登录的体验。
生成 cookie 和 claims
在 Asp.Net 的HttpContext中有身份认证相关的扩展方法,用于生成 身份认证的 cookie 以及用户登录。 authentication 的scheme 必须符合cookie handler中配置的值。
当用户登录之后,至少要生成 sub 以及 name 的 claim。 IdentityServer 同样也在 HttpContext中 提供几个 SignInAsync 扩展方法,使得使用起来更方便。
也可以生成 idp claim(identity provider 的 name),amr claim(authentication method使用),和/或 auth_time claim(用户authentication的时间)。如果不提供这些值, identityServer 会提供默认的值。
IdentityServer4 sign-in的更多相关文章
- .netcore2.1 使用IdentityServer4 生成Token验证
每个新技术权限验证都有一套机制,之前项目WebApi接口权限验证用的是Owin做为权限验证,而.netcore权限限制使用的是IdentityServer4,采用JWT的方法验证token. 首先使用 ...
- IdentityServer4 手动验签及日志记录
IdentityServer4的基础知识和使用方式网上有很多特别优秀的文章,如果有对其不了解的推荐阅读一下下面的两篇文章 http://www.ruanyifeng.com/blog/2014/05/ ...
- IdentityServer4 使用OpenID Connect添加用户身份验证
使用IdentityServer4 实现OpenID Connect服务端,添加用户身份验证.客户端调用,实现授权. IdentityServer4 目前已更新至1.0 版,在之前的文章中有所介绍.I ...
- IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习保护API
IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习之保护API. 使用IdentityServer4 来实现使用客户端凭据保护ASP.N ...
- The certificate used to sign ***has either expired or has been revoked. An updated certificate is required to sign and install the application
真机测试的时候弹出这样的提示:The certificate used to sign ***has either expired or has been revoked. An updated ce ...
- Xocde一次版本升级遇到的问题 (Code Sign Error)
因为Xcode对ios版本的支持问题,我对XCode进行了一次升级,导致原来还好的项目代码出现了编译时错误. Code Sign Error failed with exit code 1 问题就在于 ...
- 【转】App开放接口api安全性—Token签名sign的设计与实现
前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...
- iOS 证书Bug The identity used to sign the executable is no longer valid 解决方案
现象:The identity used to sign the executable is no longer valid Please verify that your device’s cloc ...
- 微信连WiFi expired timestamp 和sign错误小坑解决
0.微信连WiFi需要时间戳毫秒,但是PHP本身没有自带这个函数.但是相对来说,Java和js获取毫秒时间戳就比较方便. 既然PHP没有,那么就自己写一个获取毫秒时间戳的函数,否则就会失败.实在懒得写 ...
- 真机测试及布署Code Sign error问题总结
Code Sign error: Certificate identity 'iPhone Developer: idf (XR9HN3TD7E)' appears more than once in ...
随机推荐
- Linux进程管理(一、 基本概念和数据结构)
被问到两个问题, 后来想了下如果要讲明白还不太容易,需要对进程的概念,进程管理有清晰的认识: 1. 父进程打开了一个文件,然后通过fork创建一个子进程, 子进程是否共享父进程的文件描述符? 2. 在 ...
- python系列之(4)豆瓣图书《平凡的世界》书评及情感分析
本篇主要是通过对豆瓣图书<平凡的世界>短评进行抓取并进行分析,并用snowNLP对其进行情感分析. 用到的模块有snowNLP,是一个python库,用来进行情感分析. 1.抓取数据 我们 ...
- DRP 2016-06-30 16:36 314人阅读 评论(21) 收藏
学习drp有一段时间了,其实从很久以前,再提高班的学习就已经不是单纯的学习,学习总是伴随着项目.这就使得我们的学习不可能全天的,大把大把时间的学习只出现在第一和第二年,所以,各自珍惜吧. DRP(Di ...
- 微服务开源生态报告 No.2
通常,我们都会通过在 GitHub 上订阅邮件列表,来了解社区动态.这一次,我们联合以上各开源项目的负责人,发布「微服务开源生态报告」,汇集各个开源项目近期的社区动态,帮助开发者们更高效的了解到各开源 ...
- 洛谷P1049 装箱问题
//01背包 价值等于体积 求所剩最小体积 #include<bits/stdc++.h> using namespace std; ; ; int c,n,v[maxn],f[maxv] ...
- Go 语言开发工具
Go 语言开发工具 LiteIDE LiteIDE是一款开源.跨平台的轻量级Go语言集成开发环境(IDE). 支持的操作系统 Windows x86 (32-bit or 64-bit) Linux ...
- 为 Ubuntu 18.04 添加开机自动加载 ntfs分区 功能
注意:Ubuntu终端命令是区分大小写的 1,准备的: ntfs-3g -- 提供ntfs读写支持(一般说来是自带的,若没有,可是使用 sudo apt-get isntall ntfs-3g ...
- H3C 对等通信
- ip2long与long2IP 分析
<?php $ip='47.93.97.127'; $long=sprintf("%u",ip2long($ip));//string(9) "794648959& ...
- Windows Community Toolkit 3.0 新功能 在WinForms 和 WPF 使用 UWP 控件
本文告诉大家一个令人震惊的消息,Windows Community Toolkit 有一个大更新,现在的版本是 3.0 .最大的提升就是 WinForm 和 WPF 程序可以使用部分 UWP 控件. ...