token-authentication-example icon indicating copy to clipboard operation
token-authentication-example copied to clipboard

使用token+username作为key把当前时间戳也存入redis

Open xm5646 opened this issue 6 years ago • 3 comments

使用token+username作为key把当前时间戳也存入redis 这一步主要用来判断用户登录的token是否快要过期了, 如果直接使用redis的查看剩余时间的API, 就不需要这么做了吧?

/** * 根据指定key 查看剩余存活时间 * @param key * @return */ public Long getFreeTime(String key) { return redisTemplate.getExpire(key);}

xm5646 avatar Oct 07 '18 19:10 xm5646

使用token+username作为key把当前时间戳也存入redis 这一步主要用来判断用户登录的token是否快要过期了, 如果直接使用redis的查看剩余时间的API, 就不需要这么做了吧?

/**

  • 根据指定key 查看剩余存活时间
  • @param key
  • @return */ public Long getFreeTime(String key) { return redisTemplate.getExpire(key);}

这样的话可以不这样做,在查询剩余时间时要注意token可能已经过期,这里的key可能为空

vzardlloo avatar Oct 09 '18 02:10 vzardlloo

是的, 如果根据key在redis中查询不到,就是token过期了.

再问个问题, VUE前段需要获取headers中的Authorization, 则需要后端暴露自定义的header, 这个设置放在那里合适? response.setHeader( "Access-Control-Expose-Headers", "Authorization");

xm5646 avatar Oct 09 '18 14:10 xm5646

是的, 如果根据key在redis中查询不到,就是token过期了.

再问个问题, VUE前段需要获取headers中的Authorization, 则需要后端暴露自定义的header, 这个设置放在那里合适? response.setHeader( "Access-Control-Expose-Headers", "Authorization");

很抱歉,不是很了解Vue的问题。:-(

vzardlloo avatar Oct 15 '18 02:10 vzardlloo