egg-passport-jwt
Install
$ npm i egg-passport-jwt --save
Usage
// {app_root}/config/plugin.jsexportspassportJwt = enable: true package: 'egg-passport-jwt';
Configuration
// {app_root}/config/config.default.jsexportspassportJwt = secret: 'your jwt secret or key';
see passport-jwt for more detail.
Example
Authenticate requests
Use app.passport.authenticate()
specifying 'jwt'
as the strategy.
// app/router.jsmodule { const router controller = app; const jwt = apppassport; router; router;};
Include the JWT in requests
The method of including a JWT in a request depends entirely on the extractor
function you choose. For example, if you use the fromAuthHeaderAsBearerToken
extractor (default), you would include an Authorization
header in your request with the
scheme set to bearer
. e.g.
Authorization: bearer JSON_WEB_TOKEN_STRING...
Verify and store user
Use app.passport.verify(async (ctx, user) => {})
hook:
// app.jsmodule { apppassport;};
Questions & Suggestions
Please open an issue here.