JWT authentication concept

前端 未结 3 1624
野趣味
野趣味 2021-02-04 11:08

I am currently working on an interaction between Angular JS app and Node.js Server (as API) with an authentication based on JSON Web Token.

But I have a question I can\'

3条回答
  •  太阳男子
    2021-02-04 11:19

    The strategy in the accepted answer works, but it misses the fact that the client can see the payload of a JWT. It is explained nicely in The Anatomy of a JSON Web Token.

    A JWT has 3 parts. The first two, header and payload, are base64 encoded. The client can decode them easily. The payload has claims about the user, the client can use this data (user id, name, roles, token expiration) w/out having to make another request to the server.

    The third part of the JWT is the signature. It is a hash of the header, the payload, and a secret that only the server knows. The server will validate the token and user's permissions on every request.

    The client never knows the secret, it just has a token that claims to be the given user.

提交回复
热议问题