最简单的IdentityServer实现——IdentityServer
1.新建项目
新建ASP .Net Core项目IdentityServer.EasyDemo.IdentityServer,选择.net core 2.0


引用IdentityServer4

2.定义Api资源
添加一个Config.cs文件,在其中定义Api资源
Api资源指上述的Api,可以有多个,在这里设置了,并且Api的配置与之匹配,IdentityServer才能识别那个Api
eg.IdentityServer项目的Api资源池里面有一个名叫"api1"的Api资源,Api项目中设置ApiName为"api1",则双方匹配
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
//参数是资源名称,资源显示名称
new ApiResource("api1", "My API")
};
}
3.定义客户端Client
继续在Config.cs中添加Client
Client指的是各个调用服务的客户端,可以有多个
用户要设置ClientId,这是它的唯一标志,在Client列表里面,ClientId不能重复,ClientSecrets是用来验证用户的密码,AllowedScopes记录了它的权限范围
注意:可以多个客户端共用一个ClientId,则对于IdentityServer来说,这些客户端都是一个"Client"。这个在你的客户端都具有相同的权限范围,或者说要求完全一样的时候,可以简化为这样。
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.ClientCredentials,
// 用于验证的secret
ClientSecrets =
{
new Secret("secret".Sha256())
},
// 允许的范围
AllowedScopes = { "api1" }
}
};
}
4.配置IdentityServer
在services里面添加IdentityServer,并且将Api资源和Client集合放入内存,交给IdentityServer
public void ConfigureServices(IServiceCollection services)
{
//配置IdentityServer,包括把Api资源,Client集合,密钥保存在内存
services.AddIdentityServer()
//设置临时签名凭据
.AddDeveloperSigningCredential()
//从Config类里面读取刚刚定义的Api资源
.AddInMemoryApiResources(Config.GetApiResources())
//从Config类里面读取刚刚定义的Client集合
.AddInMemoryClients(Config.GetClients());
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseIdentityServer();
}
5.在属性中将IdentityServer项目的端口号设置为5000

6.查看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",
"frontchannel_logout_supported": true,
"frontchannel_logout_session_supported": true,
"backchannel_logout_supported": true,
"backchannel_logout_session_supported": true,
"scopes_supported": [
"api1",
"offline_access"
],
"claims_supported": [],
"grant_types_supported": [
"authorization_code",
"client_credentials",
"refresh_token",
"implicit"
],
"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"
]
}
最简单的IdentityServer实现——IdentityServer的更多相关文章
- 最简单的IdentityServer实现——项目基本结构与流程
项目结构 共分为三个组成部分: IdentityServer:用于登录.身份认证与授权 Api:提供获得授权后调用的各接口 Client(客户端,控制台):访问IdentityServer授权,再访问 ...
- .NET Core微服务之基于IdentityServer建立授权与验证服务
Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.IdentityServer的预备知识 要学习IdentityServer,事先得了解一下基于Token的验证体系,这是一个庞大的主题 ...
- IdentityServer学习目录
IdentityServer IdentityServer的基本概念与特性 IdentityServer流程图与相关术语 最简单的IdentityServer实现 最简单的IdentityServer ...
- IdentityServer4学习及简单使用
本文,主要用来记录IdentityServer4的简单使用. 一. IdentityServer的预备知识 要学习IdentityServer,需要了解下基于Token的验证体系,其中涉及到Token ...
- 微服务(入门四):identityServer的简单使用(客户端授权)
IdentityServer简介(摘自Identity官网) IdentityServer是将符合规范的OpenID Connect和OAuth 2.0端点添加到任意ASP.NET核心应用程序的中间件 ...
- 入门教程:.NET开源OpenID Connect 和OAuth解决方案IdentityServer v3 创建简单的OAuth2.0服务器,客户端和API(三)
本教程的目的在于创造尽可能简单的identityserver安装作为一个oauth2授权服务器.这应该能够让你了解一些基本功能和配置选项(完整的源代码可以发现在这里).在后面的文档中会介绍更多的高级功 ...
- 最简单的IdentityServer实现——Client
客户端控制台演示请求访问令牌,然后使用此令牌访问API 1.新建项目并添加引用 新建一个.net core的控制台程序IdentityServer.EasyDemo.Client 1 引用Iden ...
- 最简单的IdentityServer实现——Api
1.创建项目并添加引用 创建ASP.NET Core Web API项目IdentityServer.EasyDemo.Api 1 2 引用IdentityServer4.AccessToke ...
- ASP.NET Core的身份认证框架IdentityServer4--(3)令牌服务配置访问控制跟UI添加
使用密码保护API OAuth 2.0 资源所有者密码授权允许一个客户端发送用户名和密码到IdentityServer并获得一个表示该用户的可以用于访问api的Token. 该规范建议仅对" ...
随机推荐
- Java NIO详细介绍
不错的文章,推荐一下. http://www.ibm.com/developerworks/cn/education/java/j-nio/j-nio.html JavaNIO非堵塞技术实际是采取Re ...
- 【23.58%】【code forces 321E】Ciel and Gondolas
time limit per test4 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- php实现 坐标移动
php实现 坐标移动 一.总结 一句话总结:伪代码,带函数逻辑,函数这样的方式写算法程序会节约超多的时间. 1.为什么算法题数据输入最好用多组数据输入的方式? 因为都是多组数据测试,而且多组数据输入 ...
- Tomcat8及之后版本出现的The valid characters are defined in RFC 7230 and RFC 3986
升级tomcat8及更高版本带来的问题 由于使用get请求,链接中参数携带特殊字符,由于Tomcat的新版本中增加了一个新特性,就是严格按照 RFC 3986规范进行访问 解析,而 RFC 3986规 ...
- JSON 表达式
JSON语法规则: 数据在名称/值对中: 数据由逗号分隔: 大括号保存对象: 中括号保存数组 1.访问对象值: var myObj,x; myObj = {" ...
- [_UICascadingTextStorage attributesAtIndex:effectiveRange:]: Range or index out of bounds
之前写过一篇<如何更好地限制一个UITextField的输入长度>,在文章最后得到的结论是可以直接使用 UIKIT_EXTERN NSString *const UITextFieldTe ...
- 代码在线执行工具(PHP,Java,C++ 等)
http://www.it1352.com/Onlinetools 支持几十种语言的在线运行. 缺点:对请求频率限制太严格了,一分钟不到十次吧...可以清理浏览器 Cookie 之后重新访问.必须用示 ...
- uitableview顶部多出20距离, UIScollView顶部多出64距离
self.automaticallyAdjustsScrollViewInsets = NO;看 这个UIViewController的这个属性你就明白了,此属性默认为YES,这样UIViewCont ...
- 微信小程序实例:实现tabs选项卡效果
最近微信应用号是炒的如火如荼,热门满满,但是也可以发现搜索关键词出来,各类网站出现的还都是微信的官方文档解释.正好赶上这个热潮,这几天先把小程序技术文档看了个遍,就直接着手写案例了.很多组件微信内部已 ...
- C 删除字符串1字符串2
#include<stdio.h> #include<string.h> void main() { char s1[1000],s2[100],b[100]; int i,j ...