原文地址

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
};
}

更多identity resource的设置内容

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"
}
}
}
};
}

API resource 更多的设置信息

Note: resource定义的user claims 通过 IProfileService 扩展加载。

IdentityServer4 Resources的更多相关文章

  1. IdentityServer4 简单使用,包括api访问控制,openid的授权登录,js访问

    写在前面 先分享一首数摇:http://music.163.com/m/song?id=36089751&userid=52749763 其次是:对于identityServer理解并不是特别 ...

  2. IdentityServer4 实现 OpenID Connect 和 OAuth 2.0

    关于 OAuth 2.0 的相关内容,点击查看:ASP.NET WebApi OWIN 实现 OAuth 2.0 OpenID 是一个去中心化的网上身份认证系统.对于支持 OpenID 的网站,用户不 ...

  3. IdentityServer4实现Token认证登录以及权限控制

    相关知识点 不再对IdentityServer4做相关介绍,博客园上已经有人出了相关的系列文章,不了解的可以看一下: 蟋蟀大神的:小菜学习编程-IdentityServer4 晓晨Master:Ide ...

  4. ASP.NET Core的身份认证框架IdentityServer4(3)-术语的解释

    IdentityServer4 术语 IdentityServer4的规范.文档和对象模型使用了一些你应该了解的术语. 身份认证服务器(IdentityServer) IdentityServer是一 ...

  5. 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现

    本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...

  6. .NET Core IdentityServer4实战 第三章-使用EntityFramework Core进行持久化配置

    内容:本文带大家使用IdentityServer4进行使用使用EntityFramework Core进行配置和操作数据 作者:zara(张子浩) 欢迎分享,但需在文章鲜明处留下原文地址. 前两章内容 ...

  7. IdentityServer4 知多少

    1. 引言 现在的应用开发层出不穷,基于浏览器的网页应用,基于微信的公众号.小程序,基于IOS.Android的App,基于Windows系统的桌面应用和UWP应用等等,这么多种类的应用,就给应用的开 ...

  8. AspNetCore中使用Ocelot之 IdentityServer4(1)

    AspNetCore中使用Ocelot之 IdentityServer4(1) 前言: OceLot网关是基于AspNetCore 产生的可扩展的高性能的企业级Api网关,目前已经基于2.0 升级版本 ...

  9. 关于 IdentityServer4 中的 Jwt Token 与 Reference Token

    OpenID Connect(Core),OAuth 2.0(RFC 6749),JSON Web Token (JWT)(RFC 7519) 之间有着密不可分联系,对比了不同语言的实现,还是觉得 I ...

随机推荐

  1. PLAY2.6-SCALA(五) Action的组合、范围的设置以及错误的处理

    一.自定义action 从一个日志装饰器的例子开始 1.在invokeBlock方法中实现 import play.api.mvc._ class LoggingAction @Inject() (p ...

  2. Hdu 4810

    2014-05-02 15:53:50 题目连接 2013年南京现场赛的题目,现场的时候,排在我们前面的队伍基本都过了这题,我们后面的队伍也有不少过了这题,唯独我们没有.. 后来是Qingyu Sha ...

  3. GitHub Top 100 Objective-C 项目简介

    主要对当前 GitHub 排名前 100 的项目做一个简单的简介, 方便初学者快速了解到当前 Objective-C 在 GitHub 的情况. 若有任何疑问可通过微博@李锦发联系我 GitHub 地 ...

  4. 【C++】STL,vector容器操作

    C++内置的数组支持容器的机制,但是它不支持容器抽象的语义.要解决此问题我们自己实现这样的类.在标准C++中,用容器向量(vector)实现.容器向量也是一个类模板.标准库vector类型使用需要的头 ...

  5. 【NS2】trace 文件格式(转载)

    本文档是对 http://nsnam.isi.edu/nsnam/index.php/NS-2_Trace_Formats > 的翻译. 译注:本文描述的无线格Trace格式已经有些陈旧,现在一 ...

  6. poj 1085 Triangle War (状压+记忆化搜索)

    Triangle War Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2685   Accepted: 1061 Desc ...

  7. 伪元素 before 和 after 各种妙用

    大家可能对伪类和伪元素有点迷糊,在介绍具体用法之前,简单介绍下伪类和伪元素.伪类大家听的多了,伪元素可能听到的不是那么频繁,其实 CSS 对这两个是有区分的. 这里整理总结下: 有时你会发现伪类元素使 ...

  8. python元组和range

    1.元组 1)元组介绍 元组: 俗称不可变的列表.⼜被成为只读列表, 元组也是python的基本数据类型之⼀, ⽤⼩括号括起来, ⾥⾯可以放任何数据类型的数据, 查询可以. 循环也可以. 切片也可以. ...

  9. epoll简介(一)

    一:概述   1:简介 EPOLL类似于POLL,是Linux特有的一种IO多路复用的机制.它在2.5.44内核中引入. 对于大量的描述符处理,EPOLL更有优势,它提供了三个系统调用来创建管理epo ...

  10. JS高级第1天

    阶段目标 主要学习 JS 的面向对象编程思想. 对象 概念 在编程领域,任何 事 和 物都可以概括成对象. 对象概念练习 用编程思想抽象出你心仪对象的属性和方法. 对象由属性和方法组成,属性和方法都可 ...