Giter VIP home page Giter VIP logo

blog's People

Watchers

 avatar  avatar

blog's Issues

JSON Web Tokens

今天被JSON Web Token折腾了一晚上。

起因

原本用Laravel做了一个OAuth2 server。现在想用这个Laravel作为服务端产生的access token,去访问另一个用express(Node.js)做为服务端的资源。

问题

Node.js 端使用express-jwt库来验证access token。但是总是报错

UnauthorizedError: invalid algorithm
    at D:\work\projects\photographer-api\node_modules\express-jwt\lib\index.js:102:22
    at D:\work\projects\photographer-api\node_modules\jsonwebtoken\verify.js:27:18
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

思考

  1. 是不是php端产生的access token在Node.js端不认啊?

尝试

  1. 到express-jwt源代码中搜索错误信息,发现可能是算法不存在。
  2. 到laravel源代码中去搜索相关算法,无果。
  3. google jwt,找到网站https://jwt.io/ ,把access token贴进去,发现验证失败,于是怀疑php库中的算法有问题。
  4. 去查看lcobucci/jwt的源代码,没有发现。
  5. 用composer下载lcobucci/jwt源代码,自己产生token做试验,发现产生的token在网站https://jwt.io/ 可以验证通过。
  6. 如果产生token是经过sign的话,需要在右下角填入key后才能验证通过。
  7. 发现试验产生的token贴进去后跟原先贴进去的token显示出来的算法不一样,一个是“HS256”,一个是“RS256"。
  8. 这才发现,原来laravel的token是用public key签名的,需要填入public key才能被验证。

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.