JWT elaborate certification

Brother developed, it is time to realize a childhood dream, and Yihong opened!

Menlian storefront decoration how? Business, who is not a Zhendian treasure ah? The manager has asked me flower lady!

Nothing Ha! Do not worry, distorted facial features are often hidden in a pure heart.

No matter how, my Yihong be opened up.

Near the major famous handsome genius, dignitaries, local hooligans what's flock. Unusually hot, because I did not shop experience. Oversized passenger caused a problem.

"" Oh Yeah boss! You just do not know it! That was our VIP store flagship store. That can make people casually into it? So to be registered for each customer, retained their information, so as to let in after they entered the store, they find the information they stay. So we had to line up to register oh! "

"Which is not right, I just do not see Wang Gongzi has registered a thing? Loud noise and ran to the front desk?"

Flowery back: "Wang Gongzi, just out of a trip, when we went out and gave him a temporary sign, then he needs to come to the front when it reported sign, and then we look for his turn signal information based on the books so. he had to go to the front desk to verify the identity information! "

"What? I shop is for customers to consume, and you let the customer back and forth to register to play? I quickly think of ways to solve this problem."

At this time, a new small store clerk said: "The boss Why do not we give each customer a customized VIP membership card to the customer's information is recorded on the card inside, and then the customer first time when he issued to? he, after he come back with the VIP card can into the store, without having to register it! ", this kid is my provoke early Jiaojin dance, too strange name, we call him for short JWT now!

"You kid actor, it is nonsense, that in case the customer card lend it?" When it comes to flower angrily. Flower rich experience in older employees, which, indeed, is indeed true.

"Oh! I - it does not matter these days in the case of our research shop, so what? I designed this VIP card, two also slowly please listen to me." JWT said slowly.

Information fair share of such cards divided into three parts.

1, the head (Header):

Tocken algorithm name and type

2, the effective storage area (Payload):

This inside it to store information about users, user name, ah, ah gender, age, etc. Yeah, right

3, anti-counterfeit logo (Signature)

Here is a message the first two statements, in accordance with the method declaration, then we mix in our shop unique formula encryption. Ensure that others can not read, can only understand our shop.

Take a picture to illustrate it!

“看到没?右侧就是那三部分的示例。

然后我们再设定这张卡的有效期,多久之后还得重新签发一次哦,这样就没问题啦,顾客在卡有效期内就不用老去前台啦!“JWT兴奋的说到。

如花被JWT如上一说也是沉吟许久没有说话。

“明天你全权负责这套认证机制,保证我们店顾客不要因为排队而放弃来我们店消费的念头”我对JWT说。

“谢谢老板,我马上就去办”JWT得到我的首肯后一溜烟的跑了。

上面这个故事就是我要对各位说的关于传统认证和JWT认证的区别:

由于http是无状态的,传统方式如何区别谁来了?谁走了呢?

1、传统认证客户端信息保留在服务器端的内存中,这里就是我们说的session,客户端下次再来需要拿着sessionID去内存查询相关信息。记得那个可怜的王公子嘛?他就是!而上面的前台客户及时我们说的服务器端的内存。

缺点:这样做的毛病就是客户端信息都放在服务器内存中,服务器不光要提供相关资源还得存储客户端信息。当数据越来越多的时候就会臃肿无比。这就是咱们常说的设计上的热点!

JWT就不一样了:当客户端第一次携带用户名密码请求认证成功后,会返回给他一个tocken。里面有其加密过后的对于该客户端描述信息。在以后访问任何接口只需要在API后边携带该tocken就可以正常使用其API了

我再写第三版devops时就是用的JWT认证方式,为了让大家看的更清晰我再上两个图:

首先访问loginAPI:

因为用的rest_framework写的,所以自带的API调试界面

然后我们输入正确的用户名密码,进行认证

再看上面的返回值:

这个tocken值就是上面那个JWT说的VIP会员卡。分三部分哦!每个部分有一个点分开:

1 "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InJvb3QiLCJleHAiOjE1NTc1NDYzMTgsImVtYWlsIjoiMTIzQDEyMy5jb20ifQ.JRfA0t_Ft5229Bvg5gioLk2uoQ-0L30sl3MKGAqR_IQ"

至于每部分是什么?小职员JWT已经替我说清楚了。

行啦小伙伴们,是不是对JWT有了一定的了解呢?

我还没吃饭呐!先闪了!

记得来我店里玩哈!

关注公众号:

Guess you like

Origin www.cnblogs.com/devops-ITboge/p/11012796.html
jwt