Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Json web token api authorization


  • Login to see the comments

Json web token api authorization

  1. 1. API Authorization JWT @liuggio
  2. 2. JWT ISN’T Java Web Tool...
  4. 4. JSON WEB TOKEN is trendy !!! google, microsoft and many others...
  5. 5. Authentication Authorization IS NOT
  6. 6. Authentication = hotel reception Authorization = Key of the room
  7. 7. Cool it ships information that can be verified and trusted with a digital signature.
  8. 8. Coooool JWT allows the server to verify the information contained in the JWT without necessarily storing state on the server NO STATE!!!
  10. 10. Web server has its session storage old school with session storage
  11. 11. Web server session storage Web server Web server Web server Web serverdifficult to scale old school with session storage
  12. 12. eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp XVCJ9. eyJzdWIiOjEyMzQ1Njc4OTAsIm5 hbWUiOiJKb2huIERvZSIsImFkbW luIjp0cnVlfQ. eoaDVGTClRdfxUZXiPs3f8FmJDk DE_VCQFXqKxpLsts JSON WEB TOKEN
  13. 13. eyJhbGciOiJIUzI1NiIsInR5cCI 6IkpXVCJ9. eyJzdWIiOjEyMzQ1Njc4OTAs Im5hbWUiOiJKb2huIERvZSIs ImFkbWluIjp0cnVlfQ. eoaDVGTClRdfxUZXiPs3f8F mJDkDE_VCQFXqKxpLsts JSON WEB TOKEN Header Claims JSON Web Signature (JWS)
  14. 14. . . JSON WEB TOKEN
  15. 15. { "alg": "HS256", "typ": "JWT" } HEADER { "id": 1234567890, "name": "John Doe", "admin": true } CLAIMS
  16. 16. header = { "alg":"HS256" } claims = { "api_id": "debugger", "exp": 1451606400, "bha": "c23543fd68fe6c8b82691ab2b402f423" } signed = HMACSHA256( base64UrlEncode(header)+"."+base64UrlEncode(claims), "secret" ) token = base64UrlEncode(header)+"."+base64UrlEncode(claims)+"."+signed
  17. 17. HTTP REQUEST curl -X POST -H 'Authorization: BEARER eyJhbGciOiJIUzI1NiJ9. eyJhcGlfaWQiOiJkZWJ1Z2dlciIsImV4cCI6MTQ1MTYwNjQwMCwiY mhhIjoiYzIzNTQzZmQ2OGZlNmM4YjgyNjkxYWIyYjQwMmY0Mj MifQ.yC0qeyxTy_QfMBhoHdAq68KIDOaqFCJNHf6g9HBD4z8' -H "Content-Type: application/json" -d “your data”
  18. 18. JWT and API GOAL 1. Authorize request 2. Verify the sender 3. Avoid Man in the middle 4. Expiration 5. Requests Cloning
  19. 19. Advantages 1/3 ● Cross-domain / CORS: cookies + CORS don't play well across different domains. ● Stateless (a.k.a. Server side scalability): there is no need to keep a session store, the token is a self-contanined entity that conveys all the user information. The rest of the state lives in cookies or local storage on the client side. ● CDN: you can serve all the assets of your app from a CDN (e.g. javascript, HTML, images, etc.), and your server side is just the API.
  20. 20. Advantages 2/3 ● Mobile ready: when you start working on a native platform cookies are not ideal when consuming a secure API (you have to deal with cookie containers). ● CSRF: since you are not relying on cookies, you don't need to protect against cross site requests ● Performance: we are not presenting any hard perf benchmarks here, but a network roundtrip (e.g. finding a session on database) is likely to take more time than calculating an HMACSHA256 to validate a token and parsing its contents.
  21. 21. Advantages 3/3 ● Functional tests, you don't need to handle any special case for login. ● Standard-based: your API could accepts a standard JSON Web Token (JWT). This is a standard and there are multiple backend libraries (.NET, Ruby, Java,Python, PHP) and companies backing their infrastructure ● Decoupling: you are not tied to a particular authentication scheme. The token might be generated anywhere, hence your API can be called from anywhere with a single way of authenticating those calls.
  22. 22. References Tools Related articles html RFC JWT: JOSE: VIDEO José Padilla: Travis Spencer: