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. jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想)

    jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想) 一.总结 1.多看学习视频:洞悉原理,触类旁通, 2.函数封装:$.post(URL,data,callback); ...

  2. svn: E200033: database is locked解决办法

    svn执行update,却被告知database is locked! 执行 svn update,却抛出个错误警报: svn: E200033: database is locked, execut ...

  3. PatentTips - Fast awake from low power mode

    BACKGROUND Electronic devices, such as electronic book readers ("eBook reader devices"), c ...

  4. 避免if语句的深层次嵌套

    公司做了个抢红包的限制,然后ajax请求的返回字段,要进行多层逻辑的判断,想想是真恶心,虽然都是简单逻辑,而且看别人以前写的代码,发现,哎,注释能不能写上吶,像我写代码都是细致到,哪怕初学者也能看懂这 ...

  5. scala 判断对象相等/equals

    package scala_enhance.scalaextends import scala.collection.mutable.HashMap /** * scala中判断对象相等 * 原则: ...

  6. springMVC出现HTTP Status 405 - Request method 'GET' not supported错误的解决方法

    今天在写一个简单的springMVC的表单请求处理时,出现了这个问题.我的form表单用的是post方法提交,并没有使用get方法,出现这个问题时,笔者可谓是一脸懵逼. 这是form表单: 这是对po ...

  7. activity-alias详解及应用

    activity-alias标签元素众所周知,AndroidManifest是一个xml文件,它包含很多标签元素,如application.activity.receiver等,其中有一个叫做acti ...

  8. 监控Nginx服务的Shell脚本

    Nginx 虽然处理并发量比 apache 确实要强点,但它这种 php-cgi 模式不是太稳定,这点网上也有朋友总结了,我在实现项目中也感受到了. 我们一台支付机,偶尔会出现以下情况的:php-cg ...

  9. Qt写入unicode编码格式的文本(用QChar写入BOM标记,并且列出所有Qt支持的字符集)

    1.文本流设置unicode小端模式 2.写入文本前两个字节FF FE 3.字符串转成unicode编码 QList<QByteArray> list = QTextCodec::avai ...

  10. 【p094】道路游戏

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 小新正在玩一个简单的电脑游戏. 游戏中有一条环形马路,马路上有n个机器人工厂,两个相邻机器人工厂之间由 ...