08.IdentityServer4登录中心
08.IdentityServer4登录中心
IdentityServer就是一套Framework,实现了OAuth的授权
理解OAuth流程,学会怎么使用他
http://ruanyifeng.com/blog/2014/05/oauth_2_0.html
客户端模式(client credentials)
客户端模式,在使用微信支付或者支付宝支付的时候,会使用这种模式

简单的实现一个IdentityServer

首先新建webapi的项目
在我的电脑D:\MyDemos\jesse\下创建文件夹IdentityServerSample
D:\MyDemos\jesse\IdentityServerSample
然后在这个文件夹下面打开dos窗体。创建webapi的项目
dotnet new webapi --name IdentityServerCenter

D:\MyDemos\jesse\IdentityServerSample\IdentityServerCenter

视频上用VScode打开的。 我还是用VS2017打开吧
添加Nuget包
Nuget安装包:IdentityServer4

添加StartUp配置
在MVC以前添加service配置
引入命名空间 using IdentityServer4;
配置添加到依赖注入里面
services.AddIdentityServer()
.AddDeveloperSigningCredential();

添加完依赖注入以后,要使用这个Identity
//app.UseMvc();//这里我们暂时用不到MVC。这里先注释掉
app.UseIdentityServer();

然后我们在Program.cs里面
设置启动地方为5000端口
.UseUrls("http://localhost:5000")

Config.cs类
在根目录下创建 Config.cs文件
这个类是我们暂时用来初始化IdentityServer的

类里面我们会写一些静态方法
这里返回一个Resource

接下来定义Client客户端
在给一个可以访问Resource,就是这个Client呢可以访问我们那些Resource

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Models; namespace IdentityServerCenter
{
public class Config
{
public static IEnumerable<ApiResource> GetResource()
{
return new List<ApiResource>
{
new ApiResource("api","My Api")
};
}
public static IEnumerable<Client> GetClients()
{
return new List<Client>()
{
new Client()
{
ClientId="client",
AllowedGrantTypes=GrantTypes.ClientCredentials,//最简单的模式
ClientSecrets={
new Secret("secret".Sha256())
},
AllowedScopes={ "api"}
}
};
} }
}
把我们的ApiResoure加入进来

运行程序
这里我先都注释掉
这里没有添加mvc的管道也没有添加webapi
webapi和mvc实际上一个管道。

打开地址,什么也看不到
http://localhost:5000/

identityServer给我提供一个固定的地址:
http://localhost:5000/.well-known/openid-configuration
这里给我们一些基本的配置,基本的信息
{
"issuer": "http://localhost:5000",
"jwks_uri": "http://localhost:5000/.well-known/openid-configuration/jwks",
"authorization_endpoint": "http://localhost:5000/connect/authorize",
"token_endpoint": "http://localhost:5000/connect/token",
"userinfo_endpoint": "http://localhost:5000/connect/userinfo",
"end_session_endpoint": "http://localhost:5000/connect/endsession",
"check_session_iframe": "http://localhost:5000/connect/checksession",
"revocation_endpoint": "http://localhost:5000/connect/revocation",
"introspection_endpoint": "http://localhost:5000/connect/introspect",
"device_authorization_endpoint": "http://localhost:5000/connect/deviceauthorization",
"frontchannel_logout_supported": true,
"frontchannel_logout_session_supported": true,
"backchannel_logout_supported": true,
"backchannel_logout_session_supported": true,
"scopes_supported": [
"api",
"offline_access"
],
"claims_supported": [],
"grant_types_supported": [
"authorization_code",
"client_credentials",
"refresh_token",
"implicit",
"urn:ietf:params:oauth:grant-type:device_code"
],
"response_types_supported": [
"code",
"token",
"id_token",
"id_token token",
"code id_token",
"code token",
"code id_token token"
],
"response_modes_supported": [
"form_post",
"query",
"fragment"
],
"token_endpoint_auth_methods_supported": [
"client_secret_basic",
"client_secret_post"
],
"subject_types_supported": [
"public"
],
"id_token_signing_alg_values_supported": [
"RS256"
],
"code_challenge_methods_supported": [
"plain",
"S256"
]
}
这里是支持的几种模式

这里是加密的方式

会暴露一些endpoint

下一节课 我们要实现Resource。写一个API
08.IdentityServer4登录中心的更多相关文章
- 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...
- ASP.NET Core分布式项目-1.IdentityServer4登录中心
源码下载 一.添加服务端的api 1.添加NUGet包 IdentityServer4 点击下载,重新生成 2.添加Startup配置 打开Startup文件 public class Startup ...
- Asp.Net Core 中IdentityServer4 授权中心之自定义授权模式
一.前言 上一篇我分享了一篇关于 Asp.Net Core 中IdentityServer4 授权中心之应用实战 的文章,其中有不少博友给我提了问题,其中有一个博友问我的一个场景,我给他解答的还不够完 ...
- IdentityServer4 登录成功后,跳转到原来页面
IdentityServer4 登录成功后,默认会跳转到Config.Client配置的RedirectUris地址http://localhost:5003/callback.html,用于获取 T ...
- Easyui入门视频教程 第08集---登录实现 ajax button的使用
目录 ----------------------- Easyui入门视频教程 第09集---登录完善 图标自定义 Easyui入门视频教程 第08集---登录实现 ajax button的使用 ...
- Asp.Net Core 中IdentityServer4 授权中心之应用实战
一.前言 查阅了大多数相关资料,查阅到的IdentityServer4 的相关文章大多是比较简单并且多是翻译官网的文档编写的,我这里在 Asp.Net Core 中IdentityServer4 的应 ...
- IdentityServer4 登录使用数据库
业务场景: IdentityServer4 默认使用TestUser和UserStore,需要模拟和加载所有的用户数据,正式环境肯定不能这样实现,我们想从自己的数据库中读取用户信息,另外,因为 Ide ...
- 统一登录中心SSO 单点登录系统的构想
什么是单点登录?我想肯定有一部分人“望文生义”的认为单点登录就是一个用户只能在一处登录,其实这是错误的理解.单点登录指的是多个子系统只需要登录一个,其他系统不需要登录了(一个浏览器内).一个子系统退出 ...
- IdentityServer4登陆中心
1. 使用Vsual Studio Code 终端执行 dotnet new webapi --name IdentityServerSample 命令创建一个webapi 的 IdentitySer ...
随机推荐
- ubuntu + lamp + laravel 环境配置
首先是LAMP 安装顺序是 A(Apache服务器) M(Mysql) P(Php) 安装apache sudo apt-get install apache2 安装mysql sudo apt-g ...
- erlang启动参数记录
不管在erlang的shell下还是脚本里,启动参数都是非常有用的,抽空儿整理下erlang的常用启动参数: +A size 异步线程池的线程数,范围为0~1024,默认为10 +P Number ...
- 数据仓库建模与ETL的实践技巧(转载)
一.Data仓库的架构 Data仓库(Data Warehouse DW)是为了便于多维分析和多角度展现而将Data按特定的模式进行存储所建立起来的关系型Datcbase,它的Data基于OLTP源S ...
- 网络协议分析之wireshark---抓包使用
Wireshark基本介绍和学习TCP三次握手 之前写过一篇博客:用 Fiddler 来调试HTTP,HTTPS. 这篇文章介绍另一个好用的抓包工具wireshark, 用来获取网络数据封包,包括ht ...
- C#高级编程七十五天----C#使用指针
在C#中使用指针的语法 假设想在C#中使用指针,首先对项目进行过配置: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/font ...
- [深入浅出Cocoa]iOS程序性能优化
本文转载至 http://blog.csdn.net/kesalin/article/details/8762032 [深入浅出Cocoa]iOS程序性能优化 罗朝辉 (http://blog.csd ...
- 简单label控件 自制
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...
- EasyDarwin开源流媒体服务器性能优化之Work-stealing优化方案
本文转自EasyDarwin开源团队成员Alex的博客:http://blog.csdn.net/cai6811376/article/details/52400226 EasyDarwin团队的Ba ...
- ElasticSearch(一)什么是全文检索?
全文检索 全文检索,即倒排索引.
- TypeSafe Config使用
================typesafeconfig的使用==================== #1.加入依赖包 config-1.2.1.jar #2.加载配置 ConfigFactor ...