标签: jwt-simple

包含用户 ID 的 JWT 需要从数据库验证吗?

我使用 userID 和 iat(issues at)签署 JWT(JSON Web 令牌),如下所示

jwt.encode({sub: user.id, iat: timestamp}, jwtSecret);
Run Code Online (Sandbox Code Playgroud)

当我从客户端收到 JWT 时,我对其进行解码以提取用户 ID。每次我需要允许用户访问安全路由时,我是否需要通过检查它在数据库中的存在来验证用户 ID(参见第一个示例)?或者我可以假设用户就是她所说的那个人,并允许她访问安全路径?

我的感觉是我需要访问数据库来验证每个请求的用户,这会很昂贵并且违背了使用 JWT 的目的。

authentication node.js jwt jwt-simple

6
推荐指数
1
解决办法
1863
查看次数

如何修复 parser() 已弃用和 setSigningKey(java.security.Key) 已弃用?

这是我在这里面临的错误:

这是我在这里面临的错误

public boolean validateToken(String jwt){
    Jwts.parser().setSigningKey(key).parseClaimsJws(jwt);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

java json spring-boot jwt-simple

6
推荐指数
4
解决办法
2万
查看次数

Passport JWT 身份验证提取令牌

我使用 express 和 jwt-simple 来处理登录/注册和经过身份验证的请求作为中间件 api。我正在尝试创建一个 .well-known 端点,以便其他 api 可以根据发送的令牌对请求进行身份验证。

这是我的策略:

module.exports = function() {
    const opts = {};
    opts.jwtFromRequest = ExtractJwt.fromAuthHeader();
    opts.secretOrKey = securityConfig.jwtSecret;
    passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
        // User.where('id', jwt_payload.id).fetch({withRelated: 'roles'})
        console.log('jwt_payload', jwt_payload)
            User.where('id', jwt_payload.id).fetch()
            .then(user => user ? done(null, user) : done(null, false))
            .catch(err => done(err, false));
    }));
};
Run Code Online (Sandbox Code Playgroud)

这是我的登录路径:

router.post('/login', function(req, res) {
    const {username, password} = req.body;
    Promise.coroutine(function* () {
        const user = yield User.where('username', username).fetch();

    if(user) {
        const isValidPassword = yield user.validPassword(password);
        if …
Run Code Online (Sandbox Code Playgroud)

node.js express jwt jwt-simple

3
推荐指数
1
解决办法
5461
查看次数

标签 统计

jwt-simple ×3

jwt ×2

node.js ×2

authentication ×1

express ×1

java ×1

json ×1

spring-boot ×1