第20章 定义客户端 - Identity Server 4 中文文档(v1.0.0)
客户端表示可以从您的身份服务器请求令牌的应用程序。
详细信息各不相同,但您通常会为客户端定义以下常用设置:
- 唯一的客户ID
- 如果需要的秘密
- 允许与令牌服务的交互(称为授权类型)
- 身份和/或访问令牌发送到的网络位置(称为重定向URI)
- 允许客户端访问的范围列表(也称为资源)
注意
在运行时,通过实现来检索客户端IClientStore
。这允许从任意数据源(如配置文件或数据库)加载它们。对于本文档,我们将使用客户端存储的内存版本。您可以通过ConfigureServices
的AddInMemoryClientsextensions
方法连接内存存储。
20.1 定义服务器到服务器通信的客户端
在这种情况下,没有交互式用户 - 服务(aka client)想要与API(aka scope)进行通信:
public class Clients
{
public static IEnumerable<Client> Get()
{
return new List<Client>
{
new Client
{
ClientId = "service.client",
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowedScopes = { "api1", "api2.read_only" }
}
};
}
}
20.2 定义基于浏览器的JavaScript客户端(例如SPA)以进行用户身份验证和委托访问及API
此客户端使用所谓的隐式流来从JavaScript请求身份和访问令牌:
var jsClient = new Client
{
ClientId = "js",
ClientName = "JavaScript Client",
ClientUri = "http://identityserver.io",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "http://localhost:7017/index.html" },
PostLogoutRedirectUris = { "http://localhost:7017/index.html" },
AllowedCorsOrigins = { "http://localhost:7017" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"api1", "api2.read_only"
}
};
20.3 定义服务器端Web应用程序(例如MVC)以使用身份验证和委托API访问
交互式服务器端(或本地桌面/移动)应用程序使用混合流。此流程为您提供最佳安全性,因为访问令牌仅通过反向通道调用传输(并允许您访问刷新令牌):
var mvcClient = new Client
{
ClientId = "mvc",
ClientName = "MVC Client",
ClientUri = "http://identityserver.io",
AllowedGrantTypes = GrantTypes.Hybrid,
AllowOfflineAccess = true,
ClientSecrets = { new Secret("secret".Sha256()) },
RedirectUris = { "http://localhost:21402/signin-oidc" },
PostLogoutRedirectUris = { "http://localhost:21402/" },
FrontChannelLogoutUri = "http://localhost:21402/signout-oidc",
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"api1", "api2.read_only"
},
};
20.4 在appsettings.json中定义客户端
该AddInMemoryClients
扩展方法也支持从ASP.NET Core配置文件中添加客户端。这允许您直接从appsettings.json文件定义静态客户端:
"IdentityServer": {
"IssuerUri": "urn:sso.company.com",
"Clients": [
{
"Enabled": true,
"ClientId": "local-dev",
"ClientName": "Local Development",
"ClientSecrets": [ { "Value": "<Insert Sha256 hash of the secret encoded as Base64 string>" } ],
"AllowedGrantTypes": [ "implicit" ],
"AllowedScopes": [ "openid", "profile" ],
"RedirectUris": [ "https://localhost:5001/signin-oidc" ],
"RequireConsent": false
}
]
}
然后将配置部分传递给AddInMemoryClients
方法:
AddInMemoryClients(configuration.GetSection("IdentityServer:Clients"))
第20章 定义客户端 - Identity Server 4 中文文档(v1.0.0)的更多相关文章
- 第19章 定义资源 - Identity Server 4 中文文档(v1.0.0)
您通常在系统中定义的第一件事是您要保护的资源.这可能是您的用户的身份信息,如个人资料数据或电子邮件地址,或访问API. 注意 您可以使用C#对象模型定义资源 - 或从数据存储加载它们.IResourc ...
- 第62章 EntityFramework支持 - Identity Server 4 中文文档(v1.0.0)
为IdentityServer中的配置和操作数据扩展点提供了基于EntityFramework的实现.EntityFramework的使用允许任何EF支持的数据库与此库一起使用. 这个库的仓库位于这里 ...
- 第14章 添加JavaScript客户端 - Identity Server 4 中文文档(v1.0.0)
本快速入门将展示如何构建基于浏览器的JavaScript客户端应用程序(有时称为" SPA "). 用户将登录IdentityServer,使用IdentityServer发出的访 ...
- 第36章 扩展授权 - Identity Server 4 中文文档(v1.0.0)
OAuth 2.0为令牌端点定义了标准授权类型,例如password,authorization_code和refresh_token.扩展授权是一种添加对非标准令牌颁发方案(如令牌转换,委派或自定义 ...
- 第61章 IdentityServer Options - Identity Server 4 中文文档(v1.0.0)
IssuerUri 设置将在发现文档和已颁发的JWT令牌中显示的颁发者名称.建议不要设置此属性,该属性从客户端使用的主机名中推断颁发者名称. PublicOrigin 此服务器实例的来源,例如http ...
- 第58章 Profile Service - Identity Server 4 中文文档(v1.0.0)
IdentityServer通常在创建令牌或处理对userinfo或内省端点的请求时需要有关用户的身份信息.默认情况下,IdentityServer仅具有身份验证cookie中的声明,以便为此身份数据 ...
- 第38章 刷新令牌 - Identity Server 4 中文文档(v1.0.0)
第38章 刷新令牌 由于访问令牌的生命周期有限,因此刷新令牌允许在没有用户交互的情况下请求新的访问令牌. 以下流程支持刷新令牌:授权代码,混合和资源所有者密码凭据流.需要明确授权客户端通过设置Allo ...
- 第35章 秘密(secrets) - Identity Server 4 中文文档(v1.0.0)
在某些情况下,客户端需要使用身份服务器进行身份验证,例如 在令牌端点请求令牌的机密应用程序(也称为客户端) API在内省端点验证引用令牌 为此,您可以将秘密列表分配给客户端或API资源. 秘密解析和验 ...
- 第34章 授予类型 - Identity Server 4 中文文档(v1.0.0)
授权类型是指定客户端如何与IdentityServer交互的方式.OpenID Connect和OAuth2.0规范定义了以下授权类型: Implicit Authorization code Hyb ...
随机推荐
- Java-IO流之转换流的使用和编码与解码原理
一.理论: 1.字符流和字节流区别是什么? 字符流=字节流+编码集,在实际读取的时候其实字符流还是按照字节来读取,但是会更具编码集进行查找编码集字典解析相应的字节,使得一次读取出一个字符: 2.什么是 ...
- Eureka-Client(Golang实现)
Eureka-Client Golang实现eureka-client 原理 根据Java版本的源码,可以看出client主要是通过REST请求来与server进行通信. Java版本的核心实现:co ...
- java实现注册的短信验证码
最近在做只能净化器的后台用户管理系统,需要使用手机号进行注册,找了许久才大致了解了手机验证码实现流程,今天在此和大家分享一下. 我们使用的是榛子云短信平台, 官网地址:http://smsow.zhe ...
- 《C#与.NET程序员面试宝典》学习札记
第2章 .NET概述 2.1-6~ .Net Framework / CLR / IL / Assembly IL:中间语言代码,不同语言(如C#,VB)的基于CLR的编译器编译生成的中间语言字节码, ...
- H5 和移动端 WebView 缓存机制解析与实战
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/qHm_dJBhVbv0pJs8Crp77w 作者:叶 ...
- 【RL-TCPnet网络教程】第36章 RL-TCPnet之FTP服务器
第36章 RL-TCPnet之FTP服务器 本章节为大家讲解RL-TCPnet的FTP服务器应用,学习本章节前,务必要优先学习第35章的FTP基础知识.有了这些基础知识之后,再搞本章节会有事 ...
- Android 音视频开发(一) : 通过三种方式绘制图片
版权声明:转载请说明出处:http://www.cnblogs.com/renhui/p/7456956.html 在 Android 音视频开发学习思路 里面,我们写到了,想要逐步入门音视频开发,就 ...
- [Bash]LeetCode195. 第十行 | Tenth Line
Given a text file file.txt, print just the 10th line of the file. Example: Assume that file.txt has ...
- [Swift]LeetCode572. 另一个树的子树 | Subtree of Another Tree
Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and no ...
- [Swift]LeetCode957. N天后的牢房 | Prison Cells After N Days
There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the ...