Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
REST Authentication with JWT
Search
Ignacio Anaya
November 15, 2017
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
REST Authentication with JWT
Ignacio Anaya
November 15, 2017
Transcript
53 slides
REST Authen,ca,on with JWT { REST Authen-ca-on with JWT }
- @ianaya89 1
! Nacho Anaya @ianaya89 • Full Stack Developer, Tech Trainer
& Speaker • Ambassador @Auth0 • Organizer @Vuenos_Aires { REST Authen-ca-on with JWT } - @ianaya89 2
{ REST Authen-ca-on with JWT } - @ianaya89 3
! Why token authen,ca,on? { REST Authen-ca-on with JWT }
- @ianaya89 4
! Why token authen,ca,on? > Stateless { REST Authen-ca-on with
JWT } - @ianaya89 5
! Why token authen,ca,on? > Decoupled { REST Authen-ca-on with
JWT } - @ianaya89 6
! Why token authen,ca,on? > Scalable { REST Authen-ca-on with
JWT } - @ianaya89 7
! Why JWT? { REST Authen-ca-on with JWT } -
@ianaya89 8
! Why JWT? > Standard RFC 7519 { REST Authen-ca-on
with JWT } - @ianaya89 9
! Why JWT? > Self Contained { REST Authen-ca-on with
JWT } - @ianaya89 10
! Why JWT? > Compact { REST Authen-ca-on with JWT
} - @ianaya89 11
! Why JWT? > Signed HMAC - RSA - ECDSA
{ REST Authen-ca-on with JWT } - @ianaya89 12
! Why JWT? > JSON { REST Authen-ca-on with JWT
} - @ianaya89 13
! What is JWT? { REST Authen-ca-on with JWT }
- @ianaya89 14
! What is JWT? header.payload.signature + Base64 { REST Authen-ca-on
with JWT } - @ianaya89 15
! What is JWT? { REST Authen-ca-on with JWT }
- @ianaya89 16
! Header { "alg": "HS256", "typ": "JWT" } { REST
Authen-ca-on with JWT } - @ianaya89 17
! Payload { "id": "1234567890", "name": "John Doe", "admin": true,
"iss": "https://api.com", "exp": 1510745797148 } { REST Authen-ca-on with JWT } - @ianaya89 18
! Payload { "id": "1234567890", "name": "John Doe", "admin": true,
"iss": "https://api.com", "exp": 1510745797148 } { REST Authen-ca-on with JWT } - @ianaya89 19
✍ Signature const data = base64urlEncode( header ) + '.'
+ base64urlEncode( payload ) HMACSHA256(data, 'your_secret_message') { REST Authen-ca-on with JWT } - @ianaya89 20
✍ Signature const data = base64urlEncode( header ) + '.'
+ base64urlEncode( payload ) HMACSHA256(data, 'your_secret_message') { REST Authen-ca-on with JWT } - @ianaya89 21
{ REST Authen-ca-on with JWT } - @ianaya89 22
! When to use it? { REST Authen-ca-on with JWT
} - @ianaya89 23
! When to use it? > Authen)ca)on > Informa*on Exchange
{ REST Authen-ca-on with JWT } - @ianaya89 24
! Where to use it? { REST Authen-ca-on with JWT
} - @ianaya89 25
! Where to use it? SPA's - Mobile Serverless -
IoT { REST Authen-ca-on with JWT } - @ianaya89 26
{ REST Authen-ca-on with JWT } - @ianaya89 27
! { REST Authen-ca-on with JWT } - @ianaya89 28
! REST API's { REST Authen-ca-on with JWT } -
@ianaya89 29
! How does it work with REST? { REST Authen-ca-on
with JWT } - @ianaya89 30
{ REST Authen-ca-on with JWT } - @ianaya89 31
! How does it work with REST? 1. Sends Creden+als
POST /login { "user": "ianaya89", "password": "dont-hack-me" } { REST Authen-ca-on with JWT } - @ianaya89 32
! How does it work with REST? 2. Creates JWT
const jwt = require('jsonwebtoken') // POST /login function login (req, res, next) { // Validates user credentials... const payload = { user: 'ianaya89', role: 'admin' } const token = jwt.sign(payload, 'this_is_super_secret') res.status(201).send({ token: `Bearer ${token}` }) } router.post('/login', login) { REST Authen-ca-on with JWT } - @ianaya89 33
! How does it work with REST? 3. Returns JWT
const jwt = require('jsonwebtoken') // POST /login function login (req, res, next) { // Validates user credentials... const payload = { user: 'ianaya89', role: 'admin' } const token = jwt.sign(payload, 'this_is_super_secret') res.status(201).send({ token: `Bearer ${token}` }) } router.post('/login', login) { REST Authen-ca-on with JWT } - @ianaya89 34
! How does it work with REST? 4. Gets a
resource GET /resource Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. eyJzdWIiOiIxMjM0NTY3ODkiLCJuYW1lIjoiSm9obiBEb2UiLCJhZG1pbiI6ZmFsc2V9. b99O1RrYbHtWJ3MGZXkdADZkmiLm9HNliRccKxMPDuc { REST Authen-ca-on with JWT } - @ianaya89 35
! How does it work with REST? 5. Verifies token
const jwt = require('jsonwebtoken') // GET /resource function getResource (req, res, next) { try { const payload = jwt.verify(token, 'this_is_super_secret') } catch (err) { return res.sendStatus(401) } } router.get('/resource', getResource) { REST Authen-ca-on with JWT } - @ianaya89 36
! How does it work with REST? 6. Sends response
const jwt = require('jsonwebtoken') // GET /resource function getResource (req, res, next) { try { const payload = jwt.verify(token, 'this_is_super_secret') res.send(' ! ') } catch (err) { return res.sendStatus(401) } } router.get('/resource', getResource) { REST Authen-ca-on with JWT } - @ianaya89 37
! How does it work with REST? 6. Sends response
const jwt = require('jsonwebtoken') // GET /resource function getResource (req, res, next) { try { const payload = jwt.verify(token, 'this_is_super_secret') if (payload.role !== 'admin') { return res.sendStatus(403) } res.send(' ! ') } catch (err) { return res.sendStatus(401) } } router.get('/resource', getResource) { REST Authen-ca-on with JWT } - @ianaya89 38
! Which languages are supported? { REST Authen-ca-on with JWT
} - @ianaya89 39
! Which languages are supported? > "All" of them {
REST Authen-ca-on with JWT } - @ianaya89 40
{ REST Authen-ca-on with JWT } - @ianaya89 41
! Is JWT secure? { REST Authen-ca-on with JWT }
- @ianaya89 42
! { REST Authen-ca-on with JWT } - @ianaya89 43
! Is JWT secure? ! Yes { REST Authen-ca-on with
JWT } - @ianaya89 44
! Is JWT secure? ! But... { REST Authen-ca-on with
JWT } - @ianaya89 45
{ REST Authen-ca-on with JWT } - @ianaya89 46
! Is JWT secure? > Anyone can view the content
{ REST Authen-ca-on with JWT } - @ianaya89 47
! Is JWT secure? > No one can modify it
{ REST Authen-ca-on with JWT } - @ianaya89 48
! Is JWT secure? > JWT is signed not ecnrpyted
{ REST Authen-ca-on with JWT } - @ianaya89 49
! Is JWT secure? > Keep your "secret" secret {
REST Authen-ca-on with JWT } - @ianaya89 50
! Resources • jwt.io • jwt-handbook • demo-auth-jwt-api { REST
Authen-ca-on with JWT } - @ianaya89 51
! { REST Authen-ca-on with JWT } - @ianaya89 52
! Thanks! @ianaya89 bit.ly/rest-auth-jwt { REST Authen-ca-on with JWT }
- @ianaya89 53
More Decks by Ignacio Anaya
See All by Ignacio Anaya
Security is not a feature‼️
ianaya89
2
560
Rompiendo Paradigmas Otra Vuez! 🔨📜3️⃣
ianaya89
0
180
Security is not a feature!
ianaya89
1
420
What's next in Vue 3? 🖖 3️⃣
ianaya89
0
180
What's next in Vue 3? 🖖 3️⃣
ianaya89
0
320
Vue.js, PWA & The Subway Dilemma
ianaya89
0
250
PWA with PWF
ianaya89
0
69
Decentralizing the Web with JavaScript
ianaya89
0
180
hey-devs-time-to-care-about-web-apps-security.pdf
ianaya89
0
150
Other Decks in Programming
See All in Programming
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
5.9k
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
190
Ruby から Emacs を操作したい
phigasui
0
110
Performance Optimization With LLMs
xleitix
0
260
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
1
460
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
760
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
180
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
150
Seven New Principles of Software Engineering
yegor256
0
500
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
1
200
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
96
6.9k
The SEO Collaboration Effect
kristinabergwall1
1
620
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
340
Music & Morning Musume
bryan
48
7.5k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
350
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
610
The Curious Case for Waylosing
cassininazir
1
610
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
We Are The Robots
honzajavorek
0
450
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
430
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
560