如何将护照与路由控制器结合起来?

我目前正试图执行passport-ldap和passport-jwt到我的rest API。 对于路由,我使用pleerock /路由控制器 ,它有一个授权的方式,但它与布尔和护照工作,我真的不知道。 我甚至不确定是否有可能将两者结合起来。

目前AuthorizationChecker返回false,因为我不知道如何使passport.authenticate成为一个布尔值。

useExpressServer(app, { controllers: [UserController, IssueController, LoginController], authorizationChecker: async (action: Action) => { return false; } @Authorized() @Get("/test") test(@Res() response: Response){ response.send("Test done.") } 

如何使用passport.authenticate()与路由控制授权?

要使用authenticate()您必须将其用作中间件。 这里是路由控制器如何使用中间件的链接 。 对于authenticationChecker

 import * as jwt from 'jwt-simple'; currentUserChecker: async (action: Action) => { const token = action.request.headers["authorization"]; console.log(token) let key= jwt.decode(token, "Banana"); console.log(key) let user = await mongoose.model("users").findOne({'key': key.key}); if (user != null && token != null) return user; } 

这是使用passport-jwt进行jwtauthentication的一个设置