The OAUTH
open authorization provides a secure, open, and simple standard for authorizing user resources. OAUTH
authorization does not allow third parties to access user account information, such as usernames and passwords. Therefore, a third party can obtain authorization for a user's resources from the OAUTH
provider without needing the user's username and password. This makes OAUTH
authorization secure, and the current version of OAUTH
is 2.0
.
Suppose there is a website that provides photo printing and delivery services, but all of the user's photos are stored in Google
Drive. If the user wants to print a large number of photos, there are several solutions:
Google
account, download all the photos they want to print, and then upload the photos to the cloud printing website for printing. This solution is feasible but cumbersome because it requires downloading and then uploading the photos.Google
account password to the printing website, allowing the website to access the photos. The user can then select the photos to be printed. However, this solution is highly unreliable as the printing website can access the user's account and password, potentially saving them on their backend servers. The printing website only needs to access the photo data, but at this point, the website has the same level of access as the user's Google
account, potentially compromising all the data stored in the account. If all the websites that require Google
authorization require users to provide their account passwords, the user can only revoke the authorization through password modification, which would invalidate all authorizations for other websites as well. If the website stores user authorization information in plain text and the database is compromised, all user information will be exposed. Additionally, there is a risk of phishing where the website deceives users into providing their account passwords, a common tactic employed by phishing sites through the guise of offering free items.OAUTH
open authorization, the cloud printing website can only access the data authorized by the user, restricting access to other data. The user's authorization is entirely managed on the Google
authorization website. Even if the user is not logged in to Google
when authorizing, the authorization process still takes place on the official Google
website. Therefore, the printing website cannot obtain the user's account and password. After the user grants the permission to read the photos to the printing website on the Google
authorization page, the website can access the photo information and proceed with the printing service. In simple terms, OAuth
is an authorization mechanism where the data owner tells the system to grant access to third-party applications to retrieve the data, and the system then generates a short-term access token to replace the password for the third-party application to access the resources.Third-party application
: Refers to applications by third-party providers, such as the cloud printing website mentioned earlier.HTTP service
: Represents the service provider, for example, Google
in the previous example.User Agent
: Usually a web browser used by the user.Authorization server
: The server used by the service provider to handle authentication.Resource server
: The server where the service provider stores user resources.Token
from the authorization server.In the second step of the basic flow, the application needs to obtain the user's authorization information to request a token. OAuth 2.0
defines four authorization grant types.
The authorization code grant, also known as the "authorization code flow," is the most complete and rigorous authorization mode, and it is also the most commonly used. Its main feature is the interaction between the client's back-end server and the service provider's authentication server, which avoids the transmission of tokens in the frontend. The frontend only passes an authorization code, and the authorization code needs to be exchanged for a token by the backend with the Appid and AppSecret. AppSecret and similar data need to be kept strictly confidential, so the token cannot be obtained directly from the code, making the authorization code grant mode highly secure.
The implicit grant, also known as the "implicit grant type," does not involve the third-party application's server and instead directly requests a token from the authentication server in the browser, bypassing the authorization code step. All steps are completed in the browser, and the token is visible to the visitor, and the client does not need to be authenticated.
In the resource owner password credentials grant, the user provides their username and password to the client, which then uses this information to request authorization from the service provider. In this mode, the user must provide their password to the client, but the client is not permitted to store the password. This is commonly used in cases where the client is highly trusted by the user, such as when the client is part of an operating system. The authentication server should only consider using this mode when other authorization modes are not feasible.
The client credentials grant is when the client, on its own behalf rather than on behalf of the user, authenticates with the service provider. In this mode, the user directly registers with the client, and the client then requests services from the service provider using its own credentials. Strictly speaking, this mode does not involve any authorization issues.