范围
这是AuthX范围功能的小集合. 这些瞄准镜是人可读取的,完全OAuth2-相容的,支持模式匹配和设置代数.
范围解剖
范围由3个领域组成,分别由 : 字符 :
billing:customer.abc:read.basic
|_____| |__________| |________|
| | |
realm context action
每个域包含部分,由 . 字符键.
范围
A 类 范围文字 范围总是以象征性、赠款或授权的形式存在,它已得到充分界定,随时可供资源使用.
范围文字中的分节可以是:
- "单一的"符号:
* - "多倍任意"符号:
** - 匹配图案的"替换段" :
/[a-zA-Z0-9_-]*/
例如,这些都是合法的 范围文字数字 :
billing:customer.abc:read.basic
billing:customer.*:*.basic
billing:**:read.*
范围模板
A 类 范围模板 是一个反相(超相) 范围文字中的值 范围文字,a部分 范围模板 可包含:
- 匹配图案的“ 超时段 ” :
/^\{[a-zA-Z0-9_-]+\}$/
例如,这些都是合法的 范围模板数字 :
billing:customer.{current_user_id}:read.basic
authx:v2.authorization..*.{current_client_id}..{current_grant_id}..{current_user_id}:**
范围模板的目的是描述一个范围,即一个价值目前尚不为人所知,但在创建赠款或授权时将会知道的范围。 范围模板从未以符号或授权方式被传递.
参数化范围
A 类 参数化范围 是一种双变量(一种方式的超集,另一种方式的子集) 范围文字中的值 范围文字,a部分 参数化范围 可包含:
- 匹配图案的"参数化段":
/^\([a-zA-Z0-9_-]+\)$/
A 中的一个域 参数化范围 不得在"参数化部分"两侧含有"多相"符号,因为"参数化部分"的位置会变得模糊.
例如,这些都是合法的 参数化范围数字 :
billing:customer.(user_id):read.basic
authx:v2.authorization..*.(client_id)..(grant_id)..(current_user_id):**
authx:v2.**.(client_id)..(grant_id)..(current_user_id):**
但以下内容无效:
authx:v2.**.(client_id)..**:**
参数化范围的目的是从特定范围文字中取出一个值. 这对于资源是有用的,在资源中,在行动开始之前知道某一数值比在行动开始之后检查范围好。 例如,一个应用程序可能想要知道所有可能的值: user_id 参数化范围 billing:customer.(user_id):read.basic 在查询数据库前 .
参数化的瞄准镜从未通过任何标志或授权.
参数化范围模板
某些功能接受一个参数化的范围模板,既允许"参数化部分",也允许"元件化部分".
安装
安装方式 npm install --save @authx/scopes
API 密码
请看 测试 用于完整的例子.
是 Valid 范围
-
isValidScope(scope: string): boolean isValidScope(collection: string[]): boolean
验证一个范围的格式是否正确.
import { validate } from "@authx/scopes";
validate("realm:context.identifier:action.**");
// => true
validate("realm:context.{identifier}:action");
// => false
validate("realm:context.***:action");
// => false
是 ValidScope 模板
-
isValidScope(scope: string): boolean isValidScope(collection: string[]): boolean
验证范围模板的格式是否正确.
import { validate } from "@authx/scopes";
validate("realm:context.identifier:action.**");
// => true
validate("realm:context.{identifier}:action");
// => true
validate("realm:context.***:action");
// => false
常态
-
normalize(scope: string): string normalize(collection: string[]): string[] - 掷出
InvalidScopeError如果范围无效.
将范围正常化为最简单的代表.
import { normalize } from "@authx/scopes";
normalize("realm:**.**:action");
// => 'realm:*.**:action'
简化
-
simplify(collection: string[]): string[] - 掷出
InvalidScopeError如果在collection无效.
简化范围收集 collection ,省略任何被收藏中另一个范围所使冗余的范围。 返回的收藏中的所有范围都实现了正常化.
import { simplify } from "@authx/scopes";
simplify(["realm:resource.*:action", "realm:**:action"]);
// => ["realm:**:action"]
等价键
-
isEqual(scopeOrCollectionA: string[] | string, scopeOrCollectionB: string[] | string): boolean - 掷出
InvalidScopeError如果在scopeOrCollectionA或者说scopeOrCollectionB无效.
检查是否 scopeOrCollectionA 财务报告和审定财务报表 scopeOrCollectionB 都是一样的,忽略了多余的范围.
import { getIntersection } from "@authx/scopes";
getIntersection(["realm:**:*"], ["realm:**:action", "realm:**:*"]);
// => true
超级集
-
isSuperset(scopeOrCollectionA: string[] | string, scopeOrCollectionB: string[] | string): boolean - 掷出
InvalidScopeError如果在scopeOrCollectionA或者说scopeOrCollectionB无效.
检查是否 scopeOrCollectionA 等于,或一个超集 scopeOrCollectionB。用于检查用户是否能够执行特定动作.
import { isSuperset } from "@authx/scopes";
isSuperset(["realm:**:*"], ["realm:**:action", "realm:**:*"]);
// => true
是 Strict 超级集
-
isStrictSuperset(scopeOrCollectionA: string[] | string, scopeOrCollectionB: string[] | string): boolean - 掷出
InvalidScopeError如果在scopeOrCollectionA或者说scopeOrCollectionB无效.
检查是否 scopeOrCollectionA 是一个严格的超级集 scopeOrCollectionB。 。 。 .
import { isStrictSuperset } from "@authx/scopes";
isStrictSuperset(["realm:**:*"], ["realm:**:action", "realm:**:*"]);
// => false
子集
-
isSubset(scopeOrCollectionA: string[] | string, scopeOrCollectionB: string[] | string): boolean - 掷出
InvalidScopeError如果在scopeOrCollectionA或者说scopeOrCollectionB无效.
检查是否 scopeOrCollectionA 等于或子集为 scopeOrCollectionB。 。 。 .
import { isSubset } from "@authx/scopes";
isSubset(["realm:**:action", "realm:**:*"], ["realm:**:*"]);
// => true
是 Strict 子集
-
isStrictSubset(scopeOrCollectionA: string[] | string, scopeOrCollectionB: string[] | string): boolean - 掷出
InvalidScopeError如果在scopeOrCollectionA或者说scopeOrCollectionB无效.
检查是否 scopeOrCollectionA 是一个严格的子集 scopeOrCollectionB。 。 。 .
import { isStrictSubset } from "@authx/scopes";
isStrictSubset(["realm:**:action", "realm:**:*"], ["realm:**:*"]);
// => false
获取接口
-
getIntersection(scopeOrCollectionA: string[] | string, scopeOrCollectionB: string[] | string): string[] - 掷出
InvalidScopeError如果在scopeOrCollectionA或者说scopeOrCollectionB无效.
获取交叉点 scopeOrCollectionA 财务报告和审定财务报表 scopeOrCollectionB,返回一组代表所有相交点的瞄准镜,或两种输入都具有的每一种能力.
import { getIntersection } from "@authx/scopes";
getIntersection(["realm:resource.*:action.*"], ["realm:**:action.read"]);
// => ["realm:resource.*:action.read"]
获取偏差
-
getDifference(collectionA: string[], collectionB: string[]): string[] - 掷出
InvalidScopeError如果在collectionA或者说collectionB无效.
获取 collectionA 财务报告和审定财务报表 collectionB,返回在 collectionB 但是没有 collectionA。返回的收藏中包含规范范围 已写入 collectionB,即使返回范围与 collectionA。 。 。 .
import { getDifference } from "@authx/scopes";
getDifference(
["realm:resource.*:action.*"],
["realm:resource.foo:action.read", "realm:other:action.read"],
);
// => ["realm:other:action.read"]
有接口
-
hasIntersection(scopeOrCollectionA: string[] | string, scopeOrCollectionB: string[] | string): string[] - 掷出
InvalidScopeError如果在scopeOrCollectionA或者说scopeOrCollectionB无效.
检查是否 scopeOrCollectionA 财务报告和审定财务报表 scopeOrCollectionB 交叉键。 在检查用户是否能够执行由该选项所代表的动作的任何子集时,此功能是有用的 subject 范围.
import { hasIntersection } from "@authx/scopes";
hasIntersection(["realm:resource.*:action.*"], ["realm:**:action.read"]);
// => true
发展
脚本
这些脚本可以使用 npm run <script>。 。 。 .
format
使用更漂亮的格式化此软件包中的代码 .
lint
对照更美的和斯林特的规则检查此套件的内容 .
prepare
构建来自 /src 页:1 /dist 带有优化的目录.
prepare:development
构建来自 /src 页:1 /dist 目录,并随着对源文件的修改而重建.
test
运行全部测试 /dist 目录.
test:development
运行全部测试 /dist 目录,并在更改时重新运行测试.
文件
弧线
这持有库的源代码.
盘点
编译和捆绑的代码 最终在这里分发。 这被git忽略了.