. , Base64 Decode , !
, :
- : , : .
, .
. JWT . token . : Header.PayLoad.Signature. , .
- Header. - :
{"typ":"JWT","alg":"HS256"}
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9 eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9 Base64 Decode. , , , ! , https://www.base64decode.org/ .
header . json ( , , , , , , , admin:true, user first , , JWT , )
{"username":"user","id":3,"iat":1465032622,"exp":1465050622}
, JWT, Base64 Decode ( - ). json eyJ1c2VybmFtZSI6IjEiLCJpZCI6MywiaWF0IjoxNDY1MDMyNjIyLCJleHAiOjE0NjUwNTA2MjJ9.
Header Payload. ! :
var encodedString=base64UrlEncode(header) + "." + base64UrlEncode(payload);
var signature=HMACSHA256(encodedString, 'a secret string which is kept at server');
!! ( ). . ( , !).
,
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.
eyJ1c2VybmFtZSI6IjEiLCJpZCI6MywiaWF0IjoxNDY1MDMyNjIyLCJleHAiOjE0NjUwNTA2MjJ9.
0K8TL1YS0XKnEIfI3lYs-bu2vbWHSNZsVJkN1mXtgWg
Base64 Decoded . .
The signature is used only by the server. The client sends each request with its token, the server must be sure that the client has not changed any part of the token payload (for example, change the user ID). This is where the importance of the signature line is found out, the server double-checks the signature with its secret key for each request !