Git Product home page Git Product logo

Comments (18)

lin-xin avatar lin-xin commented on August 15, 2024 2

服务端是不能让jwt在有效期内变得无效的,但是可以让即使这个token有效,也可以让用户的登录状态失效:

    1. 需要给用户添加一个字段,通过这个字段和token一起验证登录状态
    1. 也可以把这个token加进黑名单

from blog.

Elity avatar Elity commented on August 15, 2024

那么问题来了,服务端怎么单方面作废一个用户的登陆状态?

from blog.

GitHdu avatar GitHdu commented on August 15, 2024

小白问几个问题:

  1. token放localStorage里面会有安全问题吗

2.例子中好像没有token验证的代码

from blog.

lin-xin avatar lin-xin commented on August 15, 2024

@GitHdu

  1. 如果是在公共电脑登录,绝对不安全
  2. koa-jwt已经封装了,想看的话可以看node_modules里的代码,上面已经有解析koa-jwt的代码了,再具体的话还可以看 jsonwebtoken 里的代码

from blog.

webproblem avatar webproblem commented on August 15, 2024

客户端发起请求的时候,是不是应该将 token 进行加密更安全点呢,还有登录的时候,password 也应该加密保证安全吧

from blog.

Elity avatar Elity commented on August 15, 2024

@lin-xin
如果需在在jwt中加额外的字段来标明是否失效,那么意味着服务端也需要存储这个字段,这与jwt的设计初衷是违背的。
把这个token作废也需要服务端单独存在这个token,下次再通过这个token访问才知道到底作废没,还是违背了jwt的设计初衷

from blog.

samfung09 avatar samfung09 commented on August 15, 2024

小白提问
如果当前我登录成功了页面要发生跳转,是url跳转并非ajax请求,这时要怎么带token给后台验证啊?

from blog.

lin-xin avatar lin-xin commented on August 15, 2024

@Elity 是的,jwt的设计并没有让服务器去使token失效的方法,而是通过过期时间,而且不建议设置过期时间太久。不知你有其他更好的方法不?

from blog.

Elity avatar Elity commented on August 15, 2024

@lin-xin jwt对这个貌似是无解的。 所以,如果业务有这样的需求,那就没办法使用jwt了

from blog.

dingjb avatar dingjb commented on August 15, 2024

@Elity 虽然和 jwt 设计的初衷是违背的,但不代表就不能用这种方式,只能说你可以用这种方式去补充 jwt 的缺点。

from blog.

cppfuns avatar cppfuns commented on August 15, 2024

可以数据库 存下这个token? 每次jwt 验证完,然后在查数据库,对比此token是否已变更?

from blog.

heiliuer avatar heiliuer commented on August 15, 2024

那么问题来了,服务端怎么单方面作废一个用户的登陆状态?

secret 有两部分组成,一部分全局的,一部分包含在用户数据里的。

from blog.

grace618 avatar grace618 commented on August 15, 2024

kow-jwt 可以验证token是否正确和解析的话,就不要用verify了吧,是吗

from blog.

MinWest avatar MinWest commented on August 15, 2024

token过期后更换新的token 有什么好的实现方式吗,koa的插件貌似得自己实现这些

from blog.

Vibing avatar Vibing commented on August 15, 2024

@MinWest Vibing/blog#7

@lin-xin localStorage.setItem('token_exp', new Date().getTime());中 token_exp 是用来做什么?

from blog.

EPSON-LEE avatar EPSON-LEE commented on August 15, 2024

@MinWest Vibing/blog#7

@lin-xin localStorage.setItem('token_exp', new Date().getTime());中 token_exp 是用来做什么?

个人理解是记录存入 token 时的时间戳

from blog.

plh97 avatar plh97 commented on August 15, 2024

直接存cookie不行吗

from blog.

plh97 avatar plh97 commented on August 15, 2024

为啥还得存localstorage

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.