当前位置:网站首页>JS - single sign on
JS - single sign on
2022-06-23 01:31:00 【hhzzcc_】
1、 introduction
Recently, I logged in the process at the front end of the renovation project , Some experience , Share how to achieve single sign on
2、 What is single sign on
Single sign on (Single Sign On), Also abbreviated as sso, This means that after a project is manually logged in , When accessing another project of the same login system, it will automatically log in .

3、 Realization
1、 Ideas
1、 Single point implementation
The normal login process exchanges the account and password to the backend token, Or get it from the back end through the account and password code, In use code Exchange for token, Either way , Eventually, the front end will get a token, Will be token Write to localStorage perhaps cookie, Bring this when the interface requests token Authenticate the backend , To realize the login . On this basis, we add a process , Use a public Iframe To store token, That is, each time the project logs in, it will token Save to public iframe Of localStorage in , When using it, it starts from this iframe Medium localStorage Remove from token, Simply put, each project shares one iframe To access token, Make each project share the same place token, Achieve single sign on .
2、 compatible
Because the login component uses vue2.0 Development , But some projects have started to use vue3.0 Development , Importing a component directly will result in an error , There may even be other framework projects in the future , In order to be compatible with this situation , Put the entire login into iframe To maintain , Including login interface 、 Login interface call 、token Storage and other core login processes , The external provider only contains js Of npm package , Mainly used to create iframe and iframe signal communication . Whether it's vue3.0 Or something else js The framework can directly access login components without burden
2、 Overall process

4、 Advantages and disadvantages
1、 advantage
Single sign on
The access of each frame is simple , Don't worry about compatibility , And the access party does not need to consider the interface cross domain problem
Easy to upgrade , The core processes are iframe in , Process upgrade does not need to be updated npm package
2、 shortcoming
iframe There is a white screen problem , It is suggested to add loading state
5、 Conclusion
Through the practice of this login, I also stepped on many pits , For example, all login components are based on npm Package form , Lead to vue3 Are not compatible vue2 Components , It took half a May Day holiday to reconstruct iframe form , This article mainly provides the implementation ideas , The implementation of other details is not complicated , It is mainly about the encapsulation and... Of login components iframe Communication between , A lot of knowledge and experience have been gained after the completion of the whole process .
边栏推荐
- Analysis of current mainstream video coding technology | community essay solicitation
- [template] KMP
- Unit of RMB in words
- SQL programming task05 job -sql advanced processing
- Vector 6 (inheritance)
- B tree and b+ tree
- Real topic of the 2020 Landbridge cup provincial competition - go square (dp/dfs)
- [22 summer reconstruction 1] codeworks round 791 (Div. 2)
- SQL programming task04 job - set operation
- Time complexity
猜你喜欢

MySQL - SQL execution process

Installation record of ros1noetic in Win 11

Explain the startup process of opengauss multithreading architecture in detail

Lexical Sign Sequence
![[hdu] P6964 I love counting](/img/ff/f8e79d28758c9bd3019816c8f46723.png)
[hdu] P6964 I love counting

Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe

07 project cost management
![[launch] redis Series 2: data persistence to improve availability](/img/f4/5bc7ca3e17c6656e71df515182842e.png)
[launch] redis Series 2: data persistence to improve availability

Template specialization template <>
Voice network multiplayer video recording and synthesis support offline re recording | Nuggets technology solicitation
随机推荐
Extend your kubernetes API using the aggregation API
使用aggregation API扩展你的kubernetes API
OSPF experiment in mGRE environment
Population standard deviation and sample standard deviation
Pat class A - 1012 the best rank (PIT)
Pat class a 1016 phone bills (time difference)
Webdriver and selenium Usage Summary
Big guys, 2.2.1 the CDC monitoring SQLSEVER can only get the full amount of data. Why can't we get the incremental data in the later period
SQL programming task02 job - basic query and sorting
人民币的单位的大写
C serializabledictionary serialization / deserialization
Time complexity
MySQL-Seconds_ behind_ Master accuracy error
New progress in the construction of meituan's Flink based real-time data warehouse platform
a++,++a,!,~
OOP multiple storage (class template)
[cmake command notes]target_ compile_ options
office2016+visio2016
Install MySQL (5.7+8.0) through docker and configure master-slave replication (gtid+ enhanced semi synchronization)
3DMAX modeling notes (I): introducing 3DMAX and creating the first model Hello World