Jwt 环回4中所有API的通用授权

Jwt 环回4中所有API的通用授权,jwt,authorization,loopback4,Jwt,Authorization,Loopback4,在loopback4框架中,对于任何安全API调用,我都需要对每个端点的请求进行身份验证。我不想使用这种方法,而是希望像loopback3那样全局配置验证。有什么解决办法吗 @post('/users/{userId}/orders', { responses: { '200': { description: 'User.Order model instance', content: {'application/json': {schem

loopback4
框架中,对于任何安全API调用,我都需要对每个端点的请求进行身份验证。我不想使用这种方法,而是希望像
loopback3
那样全局配置验证。有什么解决办法吗

   @post('/users/{userId}/orders', {
    responses: {
      '200': {
        description: 'User.Order model instance',
        content: {'application/json': {schema: {'x-ts-type': Order}}},
      },
    },
  })
  @authenticate('jwt')
  @authorize({resource: 'order', scopes: ['create']})
  async createOrder(
    @param.path.string('userId') userId: string,
    @requestBody() order: Order,
  ): Promise<Order> {
    await this.userRepo.orders(userId).create(order);
  }
@post('/users/{userId}/orders'{
答复:{
'200': {
描述:“User.Order模型实例”,
内容:{'application/json':{schema:{'x-ts-type':Order},
},
},
})
@身份验证('jwt')
@授权({resource:'order',作用域:['create']})
异步createOrder(
@param.path.string('userId')userId:string,
@requestBody()顺序:顺序,
):承诺{
等待这个.userRepo.orders(userId).create(order);
}

在上面提到的代码
@authenticate('jwt')
中,我们可以在一个公共文件中提到这一点吗?

在你的应用程序构造函数中,你在
this.api({…})
中有什么内容?你是否尝试在
序列中添加一个身份验证函数。ts
?@Salita你能解释一下如何以及在序列中添加到哪里吗,我建议您参考dcumentation,我可以向您保证,在application.ts级别设置注释不会对所有控制器启用它。处理此问题的唯一方法是添加一个带有@authenticate注释的基本控制器,所有其他控制器都应从该控制器继承。