1.新建项目

新建ASP .Net Core项目IdentityServer.EasyDemo.IdentityServer,选择.net core 2.0

 
1
 
2

引用IdentityServer4

 
3

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

 
1

6.查看IdentityServer的相关信息

通过这个网址查看:http://localhost:5000/.well-known/openid-configuration

 
2
{
"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的更多相关文章

  1. 最简单的IdentityServer实现——项目基本结构与流程

    项目结构 共分为三个组成部分: IdentityServer:用于登录.身份认证与授权 Api:提供获得授权后调用的各接口 Client(客户端,控制台):访问IdentityServer授权,再访问 ...

  2. .NET Core微服务之基于IdentityServer建立授权与验证服务

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 一.IdentityServer的预备知识 要学习IdentityServer,事先得了解一下基于Token的验证体系,这是一个庞大的主题 ...

  3. IdentityServer学习目录

    IdentityServer IdentityServer的基本概念与特性 IdentityServer流程图与相关术语 最简单的IdentityServer实现 最简单的IdentityServer ...

  4. IdentityServer4学习及简单使用

    本文,主要用来记录IdentityServer4的简单使用. 一. IdentityServer的预备知识 要学习IdentityServer,需要了解下基于Token的验证体系,其中涉及到Token ...

  5. 微服务(入门四):identityServer的简单使用(客户端授权)

    IdentityServer简介(摘自Identity官网) IdentityServer是将符合规范的OpenID Connect和OAuth 2.0端点添加到任意ASP.NET核心应用程序的中间件 ...

  6. 入门教程:.NET开源OpenID Connect 和OAuth解决方案IdentityServer v3 创建简单的OAuth2.0服务器,客户端和API(三)

    本教程的目的在于创造尽可能简单的identityserver安装作为一个oauth2授权服务器.这应该能够让你了解一些基本功能和配置选项(完整的源代码可以发现在这里).在后面的文档中会介绍更多的高级功 ...

  7. 最简单的IdentityServer实现——Client

    客户端控制台演示请求访问令牌,然后使用此令牌访问API 1.新建项目并添加引用 新建一个.net core的控制台程序IdentityServer.EasyDemo.Client   1 引用Iden ...

  8. 最简单的IdentityServer实现——Api

    1.创建项目并添加引用 创建ASP.NET Core Web API项目IdentityServer.EasyDemo.Api   1   2 引用IdentityServer4.AccessToke ...

  9. ASP.NET Core的身份认证框架IdentityServer4--(3)令牌服务配置访问控制跟UI添加

    使用密码保护API OAuth 2.0 资源所有者密码授权允许一个客户端发送用户名和密码到IdentityServer并获得一个表示该用户的可以用于访问api的Token. 该规范建议仅对" ...

随机推荐

  1. IIS最大并发连接数 = 队列长度 + IIS最大并发工作线程数

    深入理解IIS的多线程工作机制   首先让我们来看看IIS里面的这2个数字:最大并发连接数,队列长度.先说这2个数字在哪里看. 最大并发连接数:在IIS中选中一个网站,右键网站名称,在右键菜单中找到并 ...

  2. php 过滤js字符串代码

    $str = '<script type="text/javascript" src="dd.js"></script> 测试php正则 ...

  3. 怎样收缩超大的SharePoint_Config数据库

    前言 在已经执行了2年多的SharePointserver上,发现SharePoint_Config的数据库文件越来越大,已经达到90几个GB,收缩能够减小20几个GB,可是一周以后又会恢复到90几个 ...

  4. php实现 坐标移动

    php实现  坐标移动 一.总结 一句话总结:伪代码,带函数逻辑,函数这样的方式写算法程序会节约超多的时间. 1.为什么算法题数据输入最好用多组数据输入的方式? 因为都是多组数据测试,而且多组数据输入 ...

  5. [Grid Layout] Use auto-fill and auto-fit if the number of repeated grid tracks is not to be def

    What about the situation in which we aren’t specifying the number of columns or rows to be repeated? ...

  6. Java中a=a+b 与 a+=b差别

    一般觉得a=a+b的运行效率是低于a+=b的,由于它多进行了一步中间变量的操作,并且会多占用一个变量的空间.而Java编译器默认对其进行了优化,优化之后两条语句都当做 a+=b来运行了,所以实际上是没 ...

  7. .net程序客户端更新方案

    原文:.net程序客户端更新方案 客户端程序一个很大的不便的地方就是程序集更新,本文这里简单的介绍一种通用的客户端更新方案.这个方案依赖程序集的动态加载,具体方案如下: 将程序集存储在一个文件数据库中 ...

  8. 【NOIP2012提高组】国王游戏 贪心 + 高精度

    题目分析 题目答案不具有单调性,所以不可以二分,转而思考贪心.因为无法确定位置,所以考虑如何才能让对于每一个$1 ~ i$使得$i$的答案最大,即$1 ~ i$最后一个最优.若设对于位置$i$,$a[ ...

  9. 链接hdf5库出现错误的解决办法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 在链接hdf5库出现一些链接错误: error LNK2001: 无法解析的外部符号 _H5T_NATIVE_DOUB ...

  10. phpcms视图查询数据

    {pc:get sql="SELECT * FROM phpcms WHERE id in ($id) ORDER BY listorder ASC LIMIT 0, 1--"re ...