KEMBAR78
Json web token api authorization | PDF
API
Authorization
JWT
@liuggio
JWT
ISN’T
Java Web Tool...
JSON WEB TOKEN
JSON WEB TOKEN
is trendy !!!
google, microsoft and many others...
Authentication
Authorization
IS NOT
Authentication = hotel reception
Authorization = Key of the room
Cool
it ships information
that can be verified
and trusted
with a digital signature.
Coooool
JWT allows the server to verify the information contained in the JWT
without necessarily storing state on the server
NO STATE!!!
NO MORE COOKIEs
COOKIEs ARE BAD
Web
server
has its
session storage
old school with session storage
Web server
session storage
Web server
Web server
Web server
Web serverdifficult to scale
old school with session storage
eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp
XVCJ9.
eyJzdWIiOjEyMzQ1Njc4OTAsIm5
hbWUiOiJKb2huIERvZSIsImFkbW
luIjp0cnVlfQ.
eoaDVGTClRdfxUZXiPs3f8FmJDk
DE_VCQFXqKxpLsts
JSON WEB TOKEN
eyJhbGciOiJIUzI1NiIsInR5cCI
6IkpXVCJ9.
eyJzdWIiOjEyMzQ1Njc4OTAs
Im5hbWUiOiJKb2huIERvZSIs
ImFkbWluIjp0cnVlfQ.
eoaDVGTClRdfxUZXiPs3f8F
mJDkDE_VCQFXqKxpLsts
JSON WEB TOKEN
Header
Claims
JSON Web
Signature (JWS)
.
.
JSON WEB TOKEN
{
"alg": "HS256",
"typ": "JWT"
}
HEADER
{
"id": 1234567890,
"name": "John Doe",
"admin": true
}
CLAIMS
header = {
"alg":"HS256"
}
claims = {
"api_id": "debugger",
"exp": 1451606400,
"bha": "c23543fd68fe6c8b82691ab2b402f423"
}
signed = HMACSHA256(
base64UrlEncode(header)+"."+base64UrlEncode(claims),
"secret"
)
token = base64UrlEncode(header)+"."+base64UrlEncode(claims)+"."+signed
HTTP REQUEST
curl -X POST http://pugporn.com
-H 'Authorization: BEARER eyJhbGciOiJIUzI1NiJ9.
eyJhcGlfaWQiOiJkZWJ1Z2dlciIsImV4cCI6MTQ1MTYwNjQwMCwiY
mhhIjoiYzIzNTQzZmQ2OGZlNmM4YjgyNjkxYWIyYjQwMmY0Mj
MifQ.yC0qeyxTy_QfMBhoHdAq68KIDOaqFCJNHf6g9HBD4z8'
-H "Content-Type: application/json"
-d “your data”
JWT and API GOAL
1. Authorize request
2. Verify the sender
3. Avoid Man in the middle
4. Expiration
5. Requests Cloning
Advantages 1/3
● Cross-domain / CORS: cookies + CORS don't play well across different domains.
● Stateless (a.k.a. Server side scalability): there is no need to keep a session store,
the token is a self-contanined entity that conveys all the user information. The rest of
the state lives in cookies or local storage on the client side.
● CDN: you can serve all the assets of your app from a CDN (e.g. javascript, HTML,
images, etc.), and your server side is just the API.
Advantages 2/3
● Mobile ready: when you start working on a native platform cookies are not
ideal when consuming a secure API (you have to deal with cookie containers).
● CSRF: since you are not relying on cookies, you don't need to protect against
cross site requests
● Performance: we are not presenting any hard perf benchmarks here, but a
network roundtrip (e.g. finding a session on database) is likely to take more
time than calculating an HMACSHA256 to validate a token and parsing its
contents.
Advantages 3/3
● Functional tests, you don't need to handle any special case for login.
● Standard-based: your API could accepts a standard JSON Web
Token (JWT). This is a standard and there are multiple backend
libraries (.NET, Ruby, Java,Python, PHP) and companies backing
their infrastructure
● Decoupling: you are not tied to a particular authentication scheme.
The token might be generated anywhere, hence your API can be
called from anywhere with a single way of authenticating those calls.
References
Tools
http://jwt.io/
http://www.timestampgenerator.com/1451606400/#result
Related articles
https://auth0.com/blog/2014/01/07/angularjs-authentication-with-cookies-vs-token/
https://developer.atlassian.com/static/connect/docs/concepts/understanding-jwt.
html
https://developers.google.com/wallet/instant-buy/about-jwts
http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html
RFC
JWT: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
JOSE: https://tools.ietf.org/wg/jose/
VIDEO
José Padilla: https://www.youtube.com/watch?v=825hodQ61bg
Travis Spencer: https://www.youtube.com/watch?v=E6o3IKcQABY
@LIUGGIO
LOVEs PUG_ROMA

Json web token api authorization

Editor's Notes

  • #4 JSON Web Token (JWT) is a useful standard becoming more prevalent, because it sends information that can be verified and trusted with a digital signature. In their most basic form, JWTs allow you to sign information (referred to as claims) with a signature and can be verified at a later time with a secret signing key. The spec is also designed with more advanced features that help against man-in-the-middle and replay attacks. Why Are JWTs Important? They handle some of the problems with information passed from a client to a server. JWT allows the server to verify the information contained in the JWT without necessarily storing state on the server. As a trend, we are seeing more and more SaaS products include JWT integrations as a feature or using JWT in their product directly. Stormpath has always followed secure best practices for JWTs, in several parts of our stack, so we want to share some best practices for using JWT the right way.
  • #5 JSON Web Token (JWT) is a useful standard becoming more prevalent, because it sends information that can be verified and trusted with a digital signature. In their most basic form, JWTs allow you to sign information (referred to as claims) with a signature and can be verified at a later time with a secret signing key. The spec is also designed with more advanced features that help against man-in-the-middle and replay attacks. Why Are JWTs Important? They handle some of the problems with information passed from a client to a server. JWT allows the server to verify the information contained in the JWT without necessarily storing state on the server. As a trend, we are seeing more and more SaaS products include JWT integrations as a feature or using JWT in their product directly. Stormpath has always followed secure best practices for JWTs, in several parts of our stack, so we want to share some best practices for using JWT the right way.
  • #14 JSON Web Token (JWT) is a useful standard becoming more prevalent, because it sends information that can be verified and trusted with a digital signature. In their most basic form, JWTs allow you to sign information (referred to as claims) with a signature and can be verified at a later time with a secret signing key. The spec is also designed with more advanced features that help against man-in-the-middle and replay attacks