Slide 1

Slide 1 text

MEET NJOROGE I'm Njoroge. I run the private bookstore called XYZ.

Slide 2

Slide 2 text

About XYZ Only registered users are able to access the inventory to see what's on offer Registered users are able to Admins can add books and do a whole load of stuff Administrators get more priviledge

Slide 3

Slide 3 text

CLIENT SERVER FINDS USER ID AND ROLE YOU ARE A USER OF ID 4"" ACCESS API "I AM A USER OF ID 4 " RETURN AUTHORIZED DATA CHECK DATA FOR USER 4 LOG IN

Slide 4

Slide 4 text

SERVER LOG IN FINDS USER ID AND ROLE YOU ARE A USER OF ID 4"" ACCESS API "I AM AN ADMIN OF ID 5 " RETURN AUTHORIZED DATA CHECK DATA FOR ADMIN 5 MALICIOUS USER CHANGES ID & ROLE CLIENT

Slide 5

Slide 5 text

FINDS USER ID AND ROLE ACCESS API JWT RETURN AUTHORIZED DATA DECODES JWT TO GET USER ID AND ROLE LOG IN JWT CLIENT SERVER

Slide 6

Slide 6 text

FINDS USER ID AND ROLE VERIFICATION FAILS LOG IN CLIENT SERVER JWT ACCESS API MODIFIED JWT MODIFIES JWT

Slide 7

Slide 7 text

RESTFUL APIS SECURING WITH JWTS

Slide 8

Slide 8 text

AM I ? CLIFFORD OUMA OSS Community Manager, Open Terms Archive Frontend Developer, Applantus WHO

Slide 9

Slide 9 text

Our mission Authenticate users to see books Authorize admins only to be able to add books We are to help Njoroge implement JSON Web Tokens to his bookstore to be able to:

Slide 10

Slide 10 text

IMPLEMENTING JWT IN A RESTFUL API What to takenote when implementing JWTs to a REST API UNDERSTANDING JWTS How JWTs work under the hood SIMPLE DEMO We'll do a simple demo of the implementation WHAT WE WILL COVER 01 02 03

Slide 11

Slide 11 text

SCAN TO GET SLIDES

Slide 12

Slide 12 text

UNDERSTANDING JWTS JWT under the hood 01

Slide 13

Slide 13 text

User logs in Session ID provided Session ID used to authenticate Session-based Authentication Server validates and creates a session in DB A session ID is sent to client and saved as a cookie Session ID used in subsequent requests and authenticates user Token-based Authentication User logs in A JWT is generated upon successful login JWT provided JWT is provided in to the client and usually stored in local storage JWT used to authenticate JWT sent in auth header for subsequent requests, is verified and authenticates user

Slide 14

Slide 14 text

WHAT IS A JSON WEB TOKEN (JWT) Is an open standard 01 it is compact and self contained 02 Helps in transmission of info as JSON object 03 Is digitally signed hence trusted 03

Slide 15

Slide 15 text

PAYLOAD (YYY) JWT COMPONENTS Contains the token type and the hashing algorithm Is Base64Url encoded to form HEADER (XXX) Contains the information being transmitted (claims) Can be reserved, public or private claims Is Base64url encoded Created encoded header and payload Signs both with a secret and uses algo in the header SIGNATURE (ZZZ) XXX.YYY.ZZZ

Slide 16

Slide 16 text

IMPLEMENTING JWT Let's see how we can implement JWTs in a REST API 02

Slide 17

Slide 17 text

ACCESS TOKEN Is a JWT to give access to certain data Is short-lived BEFORE IMPLEMENTATION REFRESH TOKEN Is a JWT that helps create a new access token upon expiry Is long-lived ACCESS TOKEN Is a JWT to give access to certain data Is short-lived

Slide 18

Slide 18 text

We need to create a JWT upon login Generating a JWT We need to verify and decode JWT upon user request Verify JWT We need to allow or deny access based on authorization Confirm authorization We need to generate Generate new token upon expiry Basic implementation cases The basic scenarios that need to be catered for

Slide 19

Slide 19 text

Generating a JWT We generate both an access token and a refresh token upon successful login

Slide 20

Slide 20 text

Verifying a JWT We verify any JWT and access the payload which is used for authorization

Slide 21

Slide 21 text

Authorized? We can use the payload to confirm if one is authorized

Slide 22

Slide 22 text

Generate new access token We can generate a new access token once expired

Slide 23

Slide 23 text

LET'S DO A SIMPLE DEMO

Slide 24

Slide 24 text

CONCLUSION VERSATILE SECURE AND VERIFIABLE SELF CONTAINED & COMPACT JWTs can have various purposes: auth, info exchange e.t.c Are encrypted and signed by the issuer The JWT contains all the required info needed Why you should consider JWTs

Slide 25

Slide 25 text

THANK YOU!

Slide 26

Slide 26 text

RESOURCE PAGE GitHub Repo link: bit.ly/jwt-session-code Feedback Form: bit.ly/jwt-session-feedback Slides: bit.ly/jwt-session-slides

Slide 27

Slide 27 text

SCAN TO GET SLIDES