Slide 1

Slide 1 text

OAuth2 & JWT Authentication and Authorization protocols based on tokens

Slide 2

Slide 2 text

@kikobeats say ‘hello’!

Slide 3

Slide 3 text

BUT FIRST Basic concepts

Slide 4

Slide 4 text

who are you Authentication anonymous user? registered user? admin user?

Slide 5

Slide 5 text

what you are authorized to do Authorization

Slide 6

Slide 6 text

ON THE OTHER HAND complementary concepts

Slide 7

Slide 7 text

HTTP as REST protocol typical API design, but does it mean?

Slide 8

Slide 8 text

REpresentational State Transfer RESTful is typically used to refer to web services implementing such an architecture.

Slide 9

Slide 9 text

REST philosophy allows you to create compatible services with any device or client that supports HTTP protocol.

Slide 10

Slide 10 text

REST typically uses JSON in data format

Slide 11

Slide 11 text

The most important REST features are: ● Stateless ● Uniform ● Based on status codes ● Cacheable what is the mean of stateless?

Slide 12

Slide 12 text

The client has the responsibility to identify the request. The petitions don’t have state. Why? Scalability.

Slide 13

Slide 13 text

The cookies are used typically for storing and sharing the sessions.

Slide 14

Slide 14 text

REST + Cookies

Slide 15

Slide 15 text

The problem is that cookies have a lot of security and privacy problems: ● Hijacking ● Third-party cookies ● XSS attacks ● Cross-site request forgery (CSRF)

Slide 16

Slide 16 text

A better approach Token-based Authentication JSON Web Tokens (JWT)

Slide 17

Slide 17 text

JSON Web Token (JWT) is a compact URL-safe means of representing claims to be transferred between two parties. The claims in a JWT are encoded (base64) as a JSON object that is digitally signed using JSON Web Signature (JWS). At this moment there is a group working in creating a standard (draft 32).

Slide 18

Slide 18 text

JWT.io Example

Slide 19

Slide 19 text

REST + JWT

Slide 20

Slide 20 text

Benefits of JWT approach: ● Mobile ready ● CORS ● Performance ● More control ● Definitely less security problems...

Slide 21

Slide 21 text

The token must be stored somewhere. A good place would be in a free domain cookie. but DON’T send the cookie: sent the value inside the cookie!

Slide 22

Slide 22 text

What about OAuth2?

Slide 23

Slide 23 text

OAuth2 is an authorization architecture that enables applications to obtain limited access to user accounts on an HTTP service, such as Facebook, Twitter, GitHub.... It works by delegating user authentication to the service that hosts the user account, and authorizing third-party applications to access the user account. OAuth2 provides authorization flows for web and desktop applications, and mobile devices without sharing their credentials.

Slide 24

Slide 24 text

OAuth2 follows a token approach but in the authorization flow.

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Is better JWT than Cookies approach? Probably is the same. If you have a cookies approach without securities problems and following good practices, you are in the right way. JWT is the natural evolution of cookies and fix some issues from the beginning. We are searching security and control.

Slide 27

Slide 27 text

References ● JSON Web Token Standard Draft ● 10 Things You Should Know about Tokens – Auth0 ● Cookies vs Tokens. Getting auth right with Angular.JS – Auth0 ● Using JSON Web Tokens as API Keys – Auth0 ● JWT.io, a JWT playground