Autentisering:
Cookies vs JSON Web tokens
bild från: https://docs.google.com/drawings/d/1wtiF_UK2e4sZVorvfBUZh2UCaZq9sTCGoaDojSdwp7I/edit
Sessions lagring
Sessions lagring
bild från: https://docs.google.com/drawings/d/1wtiF_UK2e4sZVorvfBUZh2UCaZq9sTCGoaDojSdwp7I/edit
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzb21lX2lzc3VlciIsImV4cCI6MTUwMDgxOTM4MCwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.KRBf-VIq_1cPg2hiSW_WOuChVIwoeXVhPC3vAaCxatM
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzb21lX2lzc3VlciIsImV4cCI6MTUwMDgxOTM4MCwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.KRBf-VIq_1cPg2hiSW_WOuChVIwoeXVhPC3vAaCxatM
Header
Payload
Signature
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzb21lX2lzc3VlciIsImV4cCI6MTUwMDgxOTM4MCwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.KRBf-VIq_1cPg2hiSW_WOuChVIwoeXVhPC3vAaCxatM
Header
Payload
Signature
var header = {
"typ": "JWT",
"alg": "HS256"
};
var payload = {
"iss": "some_issuer",
"exp": 1500819380,
"name": "John Doe",
"admin": true
};
var signature =
HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload),'secret');
var JWT = base64UrlEncode(header) +"."+ base64UrlEncode(payload)+"."+ signature
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzb21lX2lzc3VlciIsImV4cCI6MTUwMDgxOTM4MCwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.KRBf-VIq_1cPg2hiSW_WOuChVIwoeXVhPC3vAaCxatM
Authorization: BEARER
eyJhbGciOiJIUzI1NiIsInR5cCI
6IkpXVCJ9.eyJpc3MiOiJzb21lX2lzc3VlciIsImV4cCI6MTUwMDgxOTM4MCwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.KRBf-VIq_1cPg2hiSW_WOuChVIwoeXVhPC3vAaCxatM
Referenser
http://jwt.io/
https://auth0.com/blog/2014/01/07/angularjs-authentication-with-cookies-vs-token/
Av: Anton Ledström