IdentityServer4 Resources
Resources 的定义
通常在系统中是顶一个需要保护的资源。这些资源可是用户的信息,比如身份信息或者邮箱地址,也可以是某些API的访问权限。
Note: 可以通过C#的对象模型或者通过数据库定义资源。通过实现
IResourceStore来处理这些低层次的细节。本文章使用in-memory的实现方式。
identity resources 的定义
Identity resources 是用户的Id,Name,Email数据。每一个Identity resource都有一个独立的name,并且可以赋任何的claim type值给它。这些claims将会被包含在用户的identity token里面。client 会使用 'scope' 参数去请求访问identity resouce。
OpenID Connect 规范制定了一些标准的Identity resources. 最基本的Identity resource要求提供用户的唯一识别Id-也可以叫做 subject Id. 这可以通过公开名称为 openid 的标准 identity resource 来实现.
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId()
};
}
类 IdentityResources 支持所有定义在规范中的所有的 scope(openid, email, profile, telephone, address)。 实现方式如下:
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Email(),
new IdentityResources.Profile(),
new IdentityResources.Phone(),
new IdentityResources.Address()
};
}
custom identity resources 的定义
public static IEnumerable<IdentityResource> GetIdentityResources()
{
var customProfile = new IdentityResource(
name: "custom.profile",
displayName: "Custom profile", // optional
claimTypes: new[] { "name", "email", "status" });//包含的用户claims
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
customProfile
};
}
API resources 的定义
要让clients请求某些API的access token,需要定义API resource,同时将这些APIs注册为一个scope。这一次 scope type是 Resource 类型
public static IEnumerable<ApiResource> GetApis()
{
return new[]
{
// simple API with a single scope (in this case the scope name is the same as the api name)
//这种情况下scope name和 api name 相同
new ApiResource("api1", "Some API 1"),
// expanded version if more control is needed
new ApiResource
{
Name = "api2",
// secret for using introspection endpoint
ApiSecrets =
{
new Secret("secret".Sha256())
},
// include the following using claims in access token (in addition to subject id)
UserClaims = { JwtClaimTypes.Name, JwtClaimTypes.Email },
// this API defines two scopes
Scopes =
{
new Scope()
{
Name = "api2.full_access",
DisplayName = "Full access to API 2",
},
new Scope
{
Name = "api2.read_only",
DisplayName = "Read only access to API 2"
}
}
}
};
}
Note: resource定义的user claims 通过 IProfileService 扩展加载。
IdentityServer4 Resources的更多相关文章
- IdentityServer4 简单使用,包括api访问控制,openid的授权登录,js访问
写在前面 先分享一首数摇:http://music.163.com/m/song?id=36089751&userid=52749763 其次是:对于identityServer理解并不是特别 ...
- IdentityServer4 实现 OpenID Connect 和 OAuth 2.0
关于 OAuth 2.0 的相关内容,点击查看:ASP.NET WebApi OWIN 实现 OAuth 2.0 OpenID 是一个去中心化的网上身份认证系统.对于支持 OpenID 的网站,用户不 ...
- IdentityServer4实现Token认证登录以及权限控制
相关知识点 不再对IdentityServer4做相关介绍,博客园上已经有人出了相关的系列文章,不了解的可以看一下: 蟋蟀大神的:小菜学习编程-IdentityServer4 晓晨Master:Ide ...
- ASP.NET Core的身份认证框架IdentityServer4(3)-术语的解释
IdentityServer4 术语 IdentityServer4的规范.文档和对象模型使用了一些你应该了解的术语. 身份认证服务器(IdentityServer) IdentityServer是一 ...
- 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...
- .NET Core IdentityServer4实战 第三章-使用EntityFramework Core进行持久化配置
内容:本文带大家使用IdentityServer4进行使用使用EntityFramework Core进行配置和操作数据 作者:zara(张子浩) 欢迎分享,但需在文章鲜明处留下原文地址. 前两章内容 ...
- IdentityServer4 知多少
1. 引言 现在的应用开发层出不穷,基于浏览器的网页应用,基于微信的公众号.小程序,基于IOS.Android的App,基于Windows系统的桌面应用和UWP应用等等,这么多种类的应用,就给应用的开 ...
- AspNetCore中使用Ocelot之 IdentityServer4(1)
AspNetCore中使用Ocelot之 IdentityServer4(1) 前言: OceLot网关是基于AspNetCore 产生的可扩展的高性能的企业级Api网关,目前已经基于2.0 升级版本 ...
- 关于 IdentityServer4 中的 Jwt Token 与 Reference Token
OpenID Connect(Core),OAuth 2.0(RFC 6749),JSON Web Token (JWT)(RFC 7519) 之间有着密不可分联系,对比了不同语言的实现,还是觉得 I ...
随机推荐
- html5实现下拉加载
介绍: 实现手机下拉自动加载数据. 原理: 通过检测页面内容距离加上当前滚动的距离大于或等于滚动距离总长时,调用ajax数据加载 事例: var myMoreInfo = new iMoreInfo( ...
- datepicker插件的使用
教程链接:http://www.runoob.com/jqueryui/example-datepicker.html 参数:http://hare6.blog.163.com/blog/static ...
- JavaScript--兼容问题总结
以下兼容主要面向IE8以上的兼容. 一.window.navigator浏览器信息 <script> console.log(window.navigator); // 用户浏览器的类型 ...
- Myeclipse自定义注释
1.设置模板 Windows—Preference—Java—Code Style—Code Templates 图中, Configure generated code and comments中的 ...
- 实现ios后台缩略图模糊的一种方法
http://blog.sina.com.cn/s/blog_64cfe8f00102ux5t.html 今天玩手机(Iphone)发现应用切换支付宝会变模糊,不禁感叹,细节处理的太到位了. 怎么 ...
- Datagrid添加右键菜单 标签: 三层EasyUI 2015-08-14 19:57 1029人阅读 评论(22)
最近的一个项目前台使用的EasyUI,每个界面都有DataGrid控件,按照我们的想法,应该做出来的效果是单击选中,双击可编辑,当然右键也应该出现这些菜单按钮,想的挺好,那么该如何实现呢?一开始不知道 ...
- Laravel 下的伪造跨站请求保护 CSRF#
简介# Laravel 可以轻松地保护应用程序免受跨站请求伪造(CSRF) 的攻击.跨站请求伪造是一种恶意的攻击, 他凭借已通过身份验证的用户身份来运行未经过授权的命令. Laravel 会自动为每个 ...
- Python学习(四)cPickle的用法
python中有两个类似的:pickle与cPickle:两者的关系:“cPickle – A faster pickle” pickle模块中的两个主要函数是dump()和load().dump() ...
- Redis源码解析:02链表
链表提供了高效的节点重排能力,以及顺序性的节点访问方式,因为Redis使用的C语言并没有内置这种数据结构,所以Redis自己实现了链表. 链表在Redis中的应用非常广泛,比如列表的底层实现之一就是链 ...
- hdu 1789 Doing Homework again (Greedy)
Problem - 1789 继续贪心.经典贪心算法,如果数据比较大就要用线段树来维护了. 思路很简单,只要按照代价由大到小排序,然后靠后插入即可.RE了一次,是没想到deadline可以很大.如果d ...