当前位置:网站首页>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] tcapulusdb operation and maintenance doc
- [elt.zip] openharmony paper Club - witness file compression system erofs
- 【深入理解TcaplusDB技术】Tmonitor后台一键安装
- Redis 5.0 data structure double end linked list source code analysis
- 【深入理解TcaplusDB技术】一键安装Tmonitor后台
- RMAN backup database_ Restart RMAN backup
- Current situation of China's hydraulic cylinder industry in 2020 (with application fields, policies and regulations, supply and demand status and enterprise pattern) [figure]
- LeetCode 198. Looting & dynamic planning
- 解决sublime Text3 package control 无法安装插件问题
- RMAN backup database_ Skip offline, read-only, and inaccessible files
猜你喜欢

两轮市场红海,利尔达芯智行如何乘风破浪?

【深入理解TcaplusDB技术】单据受理之创建业务指南

Svn introduction and Usage Summary

【深入理解TcaplusDB技术】TcaplusDB机型

05 virtual machine stack

Redis 5.0 data structure double end linked list source code analysis
![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]

华为发布两大昇腾计划 推动AI人才发展和科研创新

【路径规划】如何给路径增加运动对象
![[in depth understanding of tcapulusdb technology] tcapulusdb model](/img/10/f94a5e1ebeaa803c754dd77351950f.png)
[in depth understanding of tcapulusdb technology] tcapulusdb model
随机推荐
跳一跳小游戏辅助(手动版本)py代码实现
07 local method stack
158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts
【路径规划】如何给路径增加运动对象
TCP/IP 测试题(三)
Sword finger offer double pointer
LeetCode 322. Change exchange & dynamic planning
Training of long and difficult sentences in postgraduate entrance examination day87
【深入理解TcaplusDB技术】TcaplusDB业务数据备份
[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor
Analysis on policy, output and market scale of China's natural gas hydrogen production industry in 2020 [figure]
Analysis of China's medical device industry development environment (PEST) in 2021: the awareness of medical care is enhanced, and the demand for medical device products is also rising [figure]
Training of long and difficult sentences in postgraduate entrance examination day85
[in depth understanding of tcapulusdb technology] tcapulusdb regular documents
How can the self-supporting number evaluation be safer for cross-border e-commerce platforms such as Amazon, eBay, shopee, lazada, express, Wal Mart and Alibaba international?
[deeply understand tcapulusdb technology] one click installation of tmonitor background
C#泛型类案例
Current situation of China's hydraulic cylinder industry in 2020 (with application fields, policies and regulations, supply and demand status and enterprise pattern) [figure]
焕新出发,利尔智达天下
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance doc