Slide 1

Slide 1 text

JSON WEB TOKEN

Slide 2

Slide 2 text

Ivan Rosolen Graduado em Sistemas de Informação Pós-graduado em Gerência de Projetos Desenvolvedor a 15+ anos Autor de vários PHPT (testes para o PHP) Entusiasta de novas tecnologias Head of Innovation @ Arizona CTO @ Mokation

Slide 3

Slide 3 text

@ivanrosolen

Slide 4

Slide 4 text

Authentication

Slide 5

Slide 5 text

- Form Request Post/Get - OAuth - Key/Hash - Credenciais em plain text - Session Cookies

Slide 6

Slide 6 text

- Data is stored in plain text on the server - Filesystem read/write requests - Distributed/clustered applications - Redis/Sticky sessions

Slide 7

Slide 7 text

API

Slide 8

Slide 8 text

- Stateless authentication (simplifies horizontal scaling) - Prevent (mitigate) Cross-Site Request Forgery (CSRF) attacks. - Security (https) - Authorization: Bearer - 401 unauthorized / 403 forbidden

Slide 9

Slide 9 text

JOSE

Slide 10

Slide 10 text

- JWT - JWS - JWA - JWK - JWE JSON Object Signing and Encryption

Slide 11

Slide 11 text

Advantages

Slide 12

Slide 12 text

- JSON Web Tokens work across different programming languages - JWTs are self-contained - JWTs can be passed around easily and secure - Better control like “one time token” to forgot password, confirm user, request rates, access, etc. - One token to rule them all (Stateless)

Slide 13

Slide 13 text

Anatomy

Slide 14

Slide 14 text

header.claims.signature

Slide 15

Slide 15 text

Header { "typ": "JWT", "alg": "HS256" }

Slide 16

Slide 16 text

Claims - iss: The issuer of the token - sub: The subject of the token - aud: The audience of the token - exp: This will probably be the registered claim most often used. This will define the expiration in NumericDate value. The expiration MUST be after the current date/time. - nbf: Defines the time before which the JWT MUST NOT be accepted for processing - iat: The time the JWT was issued. Can be used to determine the age of the JWT - jti: Unique identifier for the JWT. Can be used to prevent the JWT from being replayed. This is helpful for a one time use token. http://www.slideshare.net/lcobucci/jwt-to-authentication-and-beyond

Slide 17

Slide 17 text

Payload / Claims { "iss": "ivanrosolen.com", "exp": 1300819380, "name": "Ivan Rosolen", "admin": true }

Slide 18

Slide 18 text

JWT eyJ0eXAiOiAiSldUIiwiYWxnIjogIkhTMjU2In0= . eyJpc3MiOiAiaXZhbnJvc29sZW4uY29tIiwiZXhwIjogMTMwM DgxOTM4MCwibmFtZSI6ICJJdmFuIFJvc29sZW4iLCJhZG1pbiI 6IHRydWV9 .

Slide 19

Slide 19 text

JWS - header - claims payload base64(header) . base64(claims)

Slide 20

Slide 20 text

JWA - secret (hmac sha256, rsa256 ....) - encrypt payload with key ‘Xuplau’

Slide 21

Slide 21 text

Signature var encodedString = base64UrlEncode(header) + "." + base64UrlEncode(payload); HMACSHA256(encodedString, 'Xuplau');

Slide 22

Slide 22 text

JWT eyJ0eXAiOiAiSldUIiwiYWxnIjogIkhTMjU2In0= . eyJpc3MiOiAiaXZhbnJvc29sZW4uY29tIiwiZXhwIjogMTMwM DgxOTM4MCwibmFtZSI6ICJJdmFuIFJvc29sZW4iLCJhZG1pbiI 6IHRydWV9 . M2FjZTM0M2ZiNjhhMzBiOWNiYTkxN2U1Zjk4YjUxOWYzMT Y3NGZlMmU4MTIzYjU1NTRkMjNlNjYzOTkyZGU2Nw==

Slide 23

Slide 23 text

Code

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Github - Session - JWT - JOSE

Slide 27

Slide 27 text

Refs

Slide 28

Slide 28 text

Github https://github.com/ivanrosolen/crud-demo JWT https://github.com/dwyl/learn-json-web-tokens http://jwt.io https://developer.atlassian.com/static/connect/docs/latest/concepts/understanding-jwt.html http://stackoverflow.com/questions/20588467/how-to-do-stateless-session-less-cookie-less-authentication Talks http://www.slideshare.net/erickt86/secureapi http://www.slideshare.net/lcobucci/jwt-to-authentication-and-beyond Luís Otávio Cobucci Oblonczyk https://github.com/lcobucci/jwt https://github.com/Ocramius/PSR7Session

Slide 29

Slide 29 text

????

Slide 30

Slide 30 text

OBRIGADO! Visite phpsp.org.br