Best
Roadmaps Guides Videos ⌘K Account
Practices
Kamran Ahmed · Visual Guide · Improve this Guide
JWT Authentication
Understand what is JWT authentication and how is it implemented
JWT-ISONWebTokens @kamranahmedse
Formoftokenbasedauthentication.BasedonanOpenStandard(RFC7519).
Canbeusedforauthorizationaswellassecureinfoexchange. ©Validatecredentials
Howdoesitwork?
•GenerateToken
Justlikeanyothertokenbasedauthstrategy. Username:Password
Onlydifferentiatorishowthetokenisgenerated.
4ISONWebToken
Characteristicsofthetoken 3Generatetokenusing
secretkey
TokenisjustanormalURL-Safestringandcan SSomesecureendpoint
TaTinHeade
bepassedtoserverinheader,bodyorURL.
Tokenisselfcontainedi.e.carriesthedata. •Responsefortherequest
Anyonecanviewthecontent.
®ValidateJWTwith
thesecretkey
Tokenhasthreepartsseparatedbyadot
XXXXXXXXXX.YYYYYYYYYY.ZZZzzzzZ
header payload signature Stringgeneratedbyhashingtheheader,
payloadwithasecreti.e.
HMACSHA256(header+ "+payload,'secret)
Stringgeneratedusingbaseb4(tokenMeta)
heldatserverandusedtogenerateandverifytokens
e.g.eyJOeXAiOiJKVIQiLCIhbGciOiJIUzIlNiJ9
Stringgeneratedusingbase64(ourData)
:
Stringgeneratedusingbase64(ourData)
TokenMeta whereourDataisthedatathatwewant
{
toembedinthetoken(akaJWTClaims).
"typ":"jwt", -Typeoftoken
e.g.eyJIc2VuSWQiOiJYRjExLTExMiMiLzaiLCJpY
"alo":"H5256"
hashingalgorithmusedforthesignaturepart
e.g.inthiscaseSHA256 OurData
"userld":"XFIl-1123",
Thesearecalledclaims
"email":"john@doe.com
Therearethreetypesofclaims "exp"."1592427938"
"iat":"1590969600*
RegisteredClaims
Standardnameswhicharereservedforappusage
PublicClaims
iat->issuedat(issuancetimestamp)
Claimswhichwecandefineanduseforour
iss->issuer(whoissuedit,appnameforexample) owndatae..guserld,email,aboveetc.
sub->tokensubject
>PrivateClaims
exp->expirytime(expirytimestamp)
Nameswithoutanymeaningtoanyoneexceptthe
aud->tokenaudience(appURLorsomestringforexample) consumerandproduceroftokens.
nbf->notbefore(timestampbeforewhichtokenisnotusable)
iti->uniquetokenidentifier(canbeusedtorevokeexistingJWTtoken)
Inoursamplepayloadabove,wehaveexpandatclaims.
Community
roadmap.sh is the 6th most starred project on GitHub and is visited by
hundreds of thousands of developers every month.
241k GitHub Stars Join on Discord
Roadmaps Best Practices Guides Videos Store YouTube
:
roadmap.sh by @kamrify
Community created roadmaps, articles, The leading DevOps resource for
resources and journeys to help you Kubernetes, cloud-native computing,
choose your path and grow in your and the latest in at-scale development,
career. deployment, and management.
© roadmap.sh · FAQs · Terms · Privacy DevOps · Kubernetes · Cloud-Native
: