SOF-Scope-Checker
在FHIR规格上用于验证SMART患者和用户级别范围的工具.
安装
yarn add @asymmetrik/sof-scope-checker
使用量
const scopeChecker = require('@asymmetrik/sof-scope-checker');
let hasValidScopes = (name, action) => {
return function (req, res, next) {
let scopes = parseScopes(req && req.user);
let { error, success } = scopeChecker(name, action, scopes);
// Log the error, wrap in operation outcome or GraphQL specific error
// You can check the type of the error as well since we use custom errors
if (error) {
next(error);
} else {
next();
}
}
};
app.get(
'/Patient',
hasValidScopes('Patient', 'read'),
patientController
)
见 扫描仪测试 用于更多使用实例.
注:返回的错误是本地JS错误的扩展. 它在错误中添加一个类型属性, 其值可能为“ 内部 ” 表示错误配置, 或“ 禁止” 表示范围不足的情况 .
参数
@asymmetrik/sof-scope-checker 导出一个函数,该函数需要三个参数.
name
资源或病人名称.
类型 : String
要求 : true
action
用户想要采取的行动 。 可能会 read, (中文(简体) ), write,或 *。 。 。 .
类型 : String
要求 : true
scopes
用户可用的范围.
类型 : Array<String>
要求 : true