There are two types of tokens in OAuth 2.0, the access token and the refresh token.
The access token represents the authorization of a specific application to access specific parts of a user’s data.Access tokens must be kept confidential in transit and in storage. The only parties that should ever see the access token are the application itself, the authorization server, and resource server.
The access token can only be used over an https connection, since passing it over a non-encrypted channel would make it trivial for third parties to intercept.
The access token response contains the following fields/parameters:
- access_token: This is a mandatory parameter, defined by a string of characters, representing an authorization on behalf of the user who authorized the request, issued to the client application.
- expires_in: This is a mandatory parameter that tells the client application for how much time the issued token is valid. This numeric value is in seconds, so in our example this token is valid for one hour.
- scope: This is an optional parameter defining which parts (or types) of protected resources can be accessed on behalf of the user. More information on access scope is provided later in this chapter.
- state: This is an optional parameter, used by the client for its own purposes, most commonly for security checks. The state value that the client application sends during the request will be the same as the one it will receive as part of the access token response, so this parameter can be used for defending against man in the middle attacks.
- refresh_token: This parameter contains a string of characters that are to be used as a parameter when requesting a new token before its expiry. It is an optional parameter and some service providers don’t use it.
A sample Access token is below
Access tokens should always expire; it’s a rare case to have an access token that has an infinite lifetime, which is also considered a bad security practice.
The client uses the refresh token to get a new access token, by contacting the authorization server and supplying the data from the refresh_token field. If this data is valid, the authorization server returns a new access token response to the client.
Refresh tokens mitigate the risk of long lived access tokens leaking into the wild. The refresh token also limits the the client credentials being sent over the wire to the auth service frequently.
When registering the client, the authorization server has to know which type of client is being registered. There are two types:
- Confidential client: These type of client applications are capable of keeping the confidentiality of the credentials secure, for example, applications running on servers in secure/restricted environments
Additionally, clients are separated in three general profiles:
- Web application: This is considered to be a confidential client application, and it’s meant to be a web application where data is stored securely on the server side of the application and cannot be accessed on the public/client side.
- User-agent-based application: This is an application that is first downloaded and then executed in a user-agent environment (for example, in a web browser). Since all data is downloaded, including credentials, this is a public application.
- Native application: This is also a public client. Applications that are installed on a device, which is used by the resource owner belong to this profile.
An endpoint is an HTTP URL string that defines the address which should be used in a certain request by an entity capable of making requests.
In OAuth 2.0 there are three important endpoints.
Two of them are server endpoints:
- Authorization endpoint: The client uses this endpoint in order to be authorized from the resource owner. If successful, the client obtains an authorization grant. There are exceptions to this behavior, like in the implicit grant flow, where the client obtains an access token from this endpoint.
- Token endpoint: The client uses this endpoint in order to supply the authorization grant and get an access token in return.
And one is a client endpoint:
- Redirection (callback) endpoint: The authorization server uses this endpoint in order to return data with authorization credentials to the client
Photo Credit : Josh