当前位置:网站首页>Detailed explanation of oauth2 - Introduction (I)
Detailed explanation of oauth2 - Introduction (I)
2022-06-25 18:36:00 【ookaoooo】
Oauth2 Detailed explanation - Introduce ( One )
1. What is? OAuth2
OAuth( Open licensing ) It's an open standard , Allow users to authorize third-party mobile applications to access information they store on another service provider , Instead of providing a user name and password to a third-party mobile app or sharing all of their data ,OAuth2.0 yes OAuth Continuation of agreement , But not backward compatible OAuth 1.0 It's completely abolished OAuth1.0.
2. Application scenarios
Third party application authorization login : stay APP Or web access to some third-party applications , For a long time, users will need to log in to another cooperation platform , such as QQ, Microblogging , Authorized login of wechat .

Native app to grant authorization :app Login request background interface , For safety certification , All requests are accompanied by token Information , If login authentication 、 Request background data .
Separate front and back single page application (spa): Front and rear end separation frame , Front end requests background data , Need to carry out oauth2 Safety certification , For example, use vue、react the latter h5 Developed app.
3 Noun description
(1) Third-party application: Third party applications , Also known as " client "(client), For example, open Zhihu , Use a third party login , choice qq Sign in , At this time, Zhihu is the client .
(2)HTTP service:HTTP Service provider , Abbreviation in this paper " Service provider ", That is to say qq.
(3)Resource Owner: Resource owner , Also known as " user "(user), The login user .
(4)User Agent: The user agent , Browser in this article .
(5)Authorization server: Authentication server , That is, the server used by the service provider to handle authentication .
(6)Resource server: Resource server , The server where the service provider stores the user generated resources . It and authentication server , Can be the same server , It can also be a different server .
4 Operation process
OAuth 2.0 The operation flow of is as follows , Excerpt from RFC 6749.

OAuth Operation process
(A) After the user opens the client , Client requires authorization from user .
(B) User agrees to authorize client .
(C) The client uses the authorization obtained in the previous step , Request token from authentication server .
(D) After the authentication server authenticates the client , Confirm no mistake , Agree to issue token .
(E) Client use token , Request resources from resource server .
(F) Resource server confirms that the token is correct , Agree to open the information to the client
Source .
5 Authorization mode
- Authorization code mode (authorization code)
- Simplified mode (implicit)
- Password mode (resource owner password credentials)
- Client mode (client credentials)
5.1 Authorization code mode
Authorization code mode (authorization code) Is the most complete function 、 The most rigorous authorization mode .
(1) User access client , The latter will direct the former to the authentication server , Suppose the user gives authorization , The authentication server directs users to the specified " Redirect URI"(redirection URI), With an authorization code .
(2) Client receives authorization code , Attach the previous " Redirect URI", Request token from authentication server :GET /oauth/token?response_type=code&client_id=test&redirect_uri= Redirect page links . Request returned successfully code Authorization code , The general effective time is 10 minute .
(3) Authentication server checked authorization code and redirection URI, After confirmation , Send access token to client (access token) And update token (refresh token).POST /oauth/token?response_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri= Redirect page links .
5.2 Simplified mode
Simplified mode (implicit grant type) Servers that do not pass through third-party applications , Request token directly from authentication server in browser , Skip the " Authorization code " This step , Hence the name . All steps in browser , The token is visible to the visitor , And the client does not need authentication .

Process steps :
(A) Clients direct users to authentication servers .
(B) The user decides whether to authorize the client .
(C) Suppose the user gives authorization , The authentication server directs the user to the specified " Redirect URI", And in URI Of Hash Part contains access tokens .
(D) Browser makes request to resource server , It does not include the last received Hash value .
(E) Resource server returns a web page , The code contained in it can be obtained Hash Token in value .
(F) The browser executes the script obtained in the previous step , Extract token .
(G) Browser sends token to client .
request URL:
GET /authorize?response_type=token&client_id=s6BhdRkqt3&state=xyz &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1 Host: server.example.com5.3 User name password mode
Password mode (Resource Owner Password Credentials Grant) in , Users provide their own user name and password to the client . Clients use this information , towards " Service provider " Asking for authorization . In this mode , The user must give his password to the client , But the client must not store the password . This is usually used when the user has a high trust in the client . In general, it does not support refresh token.

Step-by-step instructions :
(A) User provides user name and password to client .
(B) Client sends user name and password to authentication server , Request token for the backer .
(C) After confirming that the authentication server is correct , Provide access token to client .
POST /token HTTP/1.1 Host: server.example.com Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW Content-Type: application/x-www-form-urlencoded grant_type=password&username=johndoe&password=A3ddj3w<article class="hentry">
5.4 Client mode (Client Credentials Grant)
Client in its own name , Not in the name of the user , towards " Service provider " authentication . Strictly speaking , Client mode does not belong to OAuth Problems to be solved by the framework . In this mode , Users register directly with clients , Client requests in its own name " Service provider " Provide services , In fact, there is no authorization problem .

Its steps are as follows :
(A) Client authenticates to authentication server , And requires an access token .
(B) After confirming that the authentication server is correct , Provide access token to client .
A In the step , From the client HTTP request , Contains the following parameters :
- granttype: Indicates the type of Authorization , The value here is fixed to "clientcredentials", Will options .
- scope: Indicates permission range , optional .
POST /token HTTP/1.1 Host: server.example.com Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW Content-Type: application/x-www-form-urlencoded grant_type=client_credentials</article>
边栏推荐
- [in depth understanding of tcapulusdb technology] form creation and approval of document acceptance
- JVM problem replication
- 158_模型_Power BI 使用 DAX + SVG 打通制作商業圖錶幾乎所有可能
- Redis 5.0 data structure double end linked list source code analysis
- 【深入理解TcaplusDB技术】TcaplusDB常规单据
- 网络安全检测与防范 测试题(四)
- 2017 reading (word memory)
- RMAN备份数据库_管理备份窗口(Backup Window)
- Boiled peanuts
- 【深入理解TcaplusDB技术】单据受理之建表审批
猜你喜欢
![Analysis on policy, output and market scale of China's natural gas hydrogen production industry in 2020 [figure]](/img/f2/ec0fe8bec503c8788d6d549845b95c.jpg)
Analysis on policy, output and market scale of China's natural gas hydrogen production industry in 2020 [figure]
![[in depth understanding of tcapulusdb technology] form creation and approval of document acceptance](/img/7b/8c4f1549054ee8c0184495d9e8e378.png)
[in depth understanding of tcapulusdb technology] form creation and approval of document acceptance
![Analysis on market scale and supply of China's needle coke industry in 2020 [figure]](/img/79/6b08b62be8768484f548b6e18bd810.jpg)
Analysis on market scale and supply of China's needle coke industry in 2020 [figure]

158 Bar _ Modèle Power bi utilise Dax + SVG pour créer des diagrammes d'affaires presque toutes les possibilités
![Current situation and trend analysis of China's glass packaging containers in 2021: the revenue of glass packaging containers increases year by year [figure]](/img/19/d93c8647415c593de9c3c959f72d64.jpg)
Current situation and trend analysis of China's glass packaging containers in 2021: the revenue of glass packaging containers increases year by year [figure]

Basic operation details of binary search tree (BST) (complete code, including test cases)

06 local method interface
![[deeply understand tcapulusdb technology] tmonitor module architecture](/img/82/24a8502604fccb89fea9963c3f3495.png)
[deeply understand tcapulusdb technology] tmonitor module architecture
![[deeply understand tcapulusdb technology] create a game zone](/img/91/cf4eae9a4336ca407c0da805b9d909.png)
[deeply understand tcapulusdb technology] create a game zone
![Analysis on the development trend of China's intense pulsed light equipment industry in 2021: the market scale is growing, and the proportion of imported brands is large [figure]](/img/15/4477a850044136bb4b1ee92ab6df45.jpg)
Analysis on the development trend of China's intense pulsed light equipment industry in 2021: the market scale is growing, and the proportion of imported brands is large [figure]
随机推荐
Training of long and difficult sentences in postgraduate entrance examination day81
[deeply understand tcapulusdb technology] transaction execution of document acceptance
LeetCode 322. Change exchange & dynamic planning
Redis configuration (Internet access, password)
Basic operation details of binary search tree (BST) (complete code, including test cases)
2021 development status of China's cloud game industry and analysis of major service providers: Although cloud games are still in their infancy, the market prospect is huge [figure]
Hash of redis command
[elt.zip] openharmony paper Club - witness file compression system erofs
[deeply understand tcapulusdb technology] tmonitor background one click installation
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance
Redis command string
[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor
网络安全检测与防范 测试题(二)
Analysis on market scale and supply of China's needle coke industry in 2020 [figure]
将Graph Explorer搬上JupyterLab:使用GES4Jupyter连接GES并进行图探索
Training of long and difficult sentences in postgraduate entrance examination day88
Redis6
Training of long and difficult sentences in postgraduate entrance examination day92
TCP/IP 测试题(二)
Sword finger offer double pointer