Single sign-on related knowledge points

Based on the microservice multi-module architecture, each module may be deployed on different servers, so their session values ​​will be different. Therefore, there are several ways to solve the login problem.

1. Common ways of single sign-on

1.1, session broadcast mechanism implementation

        session的复制

1.2, use cookie+redis to achieve

在项目中任何一个模块进行登录,登录之后,将数据存放至两个地方。
	 1. redis:在key:(使用一些规则生成随机值【ip、用户id等】,value:存放用户数据
	 2. cookie:把redis里生成的key值放在cookie中
	 3. 访问其他模块时,发送请求会带着cookie值
 	 	 (1)、把cookie值获取,到redis中进行查询,根据key进行查询,如果查询到数据就登录。

1.3, use Token to achieve

token就是按照一定的规则【规则自定义】生成的字符串,字符串可以包含用户信息
	1、在项目中的某个模块进行登录之后,按照规则生成字符串,把登录之后的用户信息放入,返回字符串。
	    (1)、可以把字符串通过cookie返回
	    (2)、把字符串通过地址栏返回
	2、再去访问其他模块时,每次访问都在地址栏带着生成的字符串,在分模块里获取字符串,再根据字符串
	获取用户信息。如果可以获取到,就是登录   

Guess you like

Origin blog.csdn.net/qq_40738693/article/details/115346963