2017-08-16 12 views
1

私は現在、残りのAPIにpassport-ldapとpassport-jwtを実装しようとしています。ルーティングのために私はpleerock/routing-controllersを使用していますが、許可の方法がありますが、それは私が正直にわからないブーリアンとパスポートで動作します。私は2つを組み合わせることが可能かどうかもわかりません。パスポートとルーティングコントローラの組み合わせ方法は?

現在、passport.authenticateをブール値にする方法がわからないため、AuthorizationCheckerはfalseを返します。

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()のルーティング制御認可の使用方法はありますか。

+0

でJWT認証用に設定されている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を使ってこれについてグローバルなミドルウェアを考えています。 –

+0

@ØysteinAmundsen私は私の答えを編集しました –

答えて

0

authenticate()を使用するには、ミドルウェアとして使用する必要があります。ルーティングコントローラのlinkは、ミドルウェアの使い方を示しています。これは、パスポート、JWT

関連する問題