【文件属性】:
文件名称:express-jwt:connectexpress中间件,用于验证JsonWebToken(JWT)并使用属性设置req.user
文件大小:36KB
文件格式:ZIP
更新时间:2021-02-27 12:20:02
jwt express-jwt JavaScript
快递
该模块提供Express中间件,用于通过模块验证JWT( )。 解码的JWT有效负载在请求对象上可用。
安装
$ npm install express-jwt
用法
使用HS256密码的基本用法:
var jwt = require ( 'express-jwt' ) ;
app . get ( '/protected' ,
jwt ( { secret : 'shhhhhhared-secret' , algorithms : [ 'HS256' ] } ) ,
function ( req , res ) {
if ( ! req . user . admin ) return res . sendStatus ( 401 ) ;
res . sendStatus ( 200 ) ;
} ) ;
可以通过user属性在请求中使用已解码的JWT有
【文件预览】:
express-jwt-master
----lib()
--------errors()
--------index.js(4KB)
----.travis.yml(80B)
----LICENSE(1KB)
----test()
--------string_token.test.js(582B)
--------revocation.test.js(2KB)
--------multitenancy.test.js(2KB)
--------jwt.test.js(12KB)
----README.md(8KB)
----.gitignore(25B)
----bin()
--------changelog(1KB)
----CHANGELOG.md(12KB)
----package-lock.json(95KB)
----package.json(934B)