Role.getRoles(context, callback) 中引用的 "security context" 是什么

What is the "security context" referenced in Role.getRoles(context, callback)

在环回 Role.getRoles(context, callback) 中,他们在 link.

中将文档中的上下文称为 "The security context"

什么是安全上下文以及如何传递它以获取用户角色?

-如文档中所述,LoopBack 的访问控制系统是围绕几个核心概念构建的。其中 "Principal" - 一个可以被识别或认证的实体。有三个基础"principalType" - APP(LICATION), USER, ROLE。每个特定的主体对象都有一个 "principalId" - 主体的 ID - 例如 appId、userId 或 roleId。

getRoles 函数将参数 context 作为 AccessContext 实例或转换为它 (http://apidocs.loopback.io/loopback/#accesscontext) 并列出给定 principal[ 的角色=26=]。

AccessContext 函数(用于转换)也接受使用以下属性定义的单个主体:

{ principalType: 'USER', principalId: '2' }

以同样的方式我们可以在请求角色时定义上下文:

Role.getRoles({ principalType: 'USER', principalId: '2' }, (err, roles) => {
            if (err) console.log(err);
            console.log(roles);
          });

并为 ID 为“2”的用户获取一组角色 ID(包括动态)。