JWT JSON Web Token

Source: Internet
Author: User

JWT (JSON Web Token)

A specification that allows us to use JWT to deliver secure and reliable information between users and servers.

The JWT consists of three parts: header (head), Payload (load), signature (signature).

First, head header

The header is used to describe the most basic information about the JWT, such as its type and the algorithm used in the signature, to generate the JWT header head with Base64url encoding.

var base64url = require ("Base64url"); var header = {    ' typ ': ' JWT ',    ' alg ': ' hs256 '}; var base64urlheader = Base64url (json.stringify (header));

Header head:

    • Typ: Type
    • ALG: The algorithm used for signing

Second, load payload

var payload = {    "ISS": "Momobutong",    "IAT": IAT,    "exp": Exp,     "AUD": "www.example.com",    "sub": "[email protected]",    "From_user": "B" ,    " Target_user ":" A "}var base64urlpayload = Base64url (json.stringify (payload));
    • ISS: The issuer of the JWT
    • Sub: The user to which the JWT is intended
    • AUD: The party receiving the JWT
    • EXP (expires): Expiration Time (Unix timestamp)
    • IAT (issued at): Issue time

Third, Signature signature

The signature signature is composed of header, load payload and key.

var crypto = require ("crypto"); var signature = Crypto.createhmac (' sha256 ', ' Secretkey '). Update (base64urlheader+ '. ') +base64urlpayload). Digest (' Hex ');

Generate JWT

JWT JSON Web Token

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.