OAuth 2.0 grant types explained (2024)

Link to this section

Authorization determines what types of files and resources specific users can access. It’s an essential part of building secure platforms and apps, responsible for giving the right people access to the right files.

But how does authorization work in the back end? That’s where the frameworks (like OAuth 2.0) come in. This approach delegates user authentication to the service that handles a user’s account and allows third-party apps to access that account in a secure way.

In order to select the right OAuth grant type, you need to define your goals, understand the different grant types available, and what benefits they can offer to your app or platform.

What is OAuth 2.0?

Link to this section

OAuth 2.0 (a.k.a Open Authorization) is the industry standard protocol for authorization. It offers client/developer simplicity and has been designed as a means of granting access to a set of resources, while providing specific authorization flows for a range of different apps, on behalf of the user.

OAuth 2.0 provides consented access while also acting as a way to restrict actions, dictating what the client can and can’t perform. It is an authorization protocol, not an authentication protocol.

These roles define the essential components of an OAuth 2.0 system and are a part of the core specifications of the OAuth 2.0 framework:

  • OAuth owner: The user/system that owns the protected resources and can grant access to them.
  • Client: The client is the system/person who requires access and must hold the appropriate access token.
  • Authorization server: The server that receives requests from the client for access tokens. The authorization server exposes two endpoints, the authorization endpoint and the token endpoint.
  • Resource Server: This server protects the users’ resources and receives access requests from the client. The server accepts and validates access tokens and will, in turn, give access to the appropriate resources.

Plus, scopes play important roles in the OAuth 2.0 concept. They’re used to specify the exact reason for access to be granted. Scope values and the resources they relate to are dependent on the resource server.

How does OAuth 2.0 work?

Link to this section

Even before OAuth 2.0 can be used, the client must acquire their own set of unique credentials from the authorization server. This will then allow the client to identify and authenticate themselves when requesting an Access Token.

Access requests using OAuth 2.0 are initiated by the client (such as an app or website). The request, exchange, and response all follow the same general flow:

  1. The client requests authorization, which could be from the server. The server will then supply the client ID and secret to prove identity. It also provides the scopes and the endpoint to send the access token and authorization code to.
  2. The authorization server authenticates the client and verifies the request scopes are permitted.
  3. The resource owner will interact with the organization server to grant access.
  4. The authorization server redirects back to the client with the code/access token depending on the grant type.
  5. With the access token, the client will gain access to the resources, from the resource server.

OAuth grant types

Link to this section

A grant is a method of acquiring an access token. This means OAuth 2.0 grants are a set of steps that the client will have to go through to get resource access authorization. The authorization framework will provide several different grant types to address different scenarios.

In short, there’s an OAuth grant flow and type to suit most use cases.

1. Authorization Code Grant

Link to this section

Authorization Code Grant is the most widely used grant type to authorize the client.

In this scenario, the authorization server will return a single-use authorization code to the client, which is then exchanged for an access token.

This is the best option for traditional web-based apps, where the exchange can happen securely on the server side. The client’s secret cannot be stored securely so authentication during the exchange is limited to the use of the client ID alone.

2. Proof Key for Code Exchange (PKCE)

Link to this section

PKCE is a security-centric OAuth grant type. The main concept behind this grant type is proof of possession. This essentially means the client app needs to prove to the authorization server that the authorization code is authentic before being issued an access token. The PKCE flow includes a code verification measure and code challenge.

Interestingly, PKCE can be traced by the older grant type, the Implicit Grant Type. With no authorization code, the client app would receive the access token instantly after getting the end user’s consent. Since this flow took place entirely through browser redirect, it proved very risky and was not secure enough. From there, PKCE was born.

3. Device Code Grant

Link to this section

The device code grant type is used by browserless or input-constrained devices, used in the device flow to exchange a previous device code for an access token.

This grant flow usually goes like this:

  • A client authorization server receives an access request from the kitchen (usually including its client identifier)
  • End-user and device codes are created and shared by the authorization server, and the end-user receives a verification URI
  • The end-user needs to utilize a user agent by the client, and then enter the end-user code to review this request
  • The end-user is authenticated by the authorization server through this user agent, prompted to enter the user code
  • The authorization server checks this code and asks the user to accept or decline the request
  • The authorization server is asked by the client to verify if authorization is complete
  • Once the server has validated the device code received by the client, access is granted and an Access Token is issued

4. Client Credentials Grant

Link to this section

This type of grant is used specifically by clients for non-interactive applications. For example, automated processes. In this case, the application would be authenticated by using the client ID and secret.

5. Refresh Token Grant

Link to this section

This is a type of grant flow that involves the exchange of a refresh token for a new access token. This allows clients to have a valid access token without having to interact with the user.

After the client sends a POST request to the authorization server a JSON object is provided. It’s also important to remember that Refresh Tokens operate differently from Access Tokens, meaning they are never sent to resource servers and only interact with authorization servers.

Tips for choosing the right OAuth grant type

Link to this section

The first step to implementing the OAuth framework is to select the right authorization grant type to suit your case. This usually depends on your application type, but other factors weigh in too, such as the level of trust between your clients or the kind of experience you want users to have.

Here are some things to consider to help you select the right OAuth grant type::

  • First-party or third-party client: A first-party client is one you trust enough to handle the end-users authorization credentials. A third-party client is one that you don’t trust.
  • Access token owner: If you’re authorizing a machine to access resources and you won’t require the permission of a user to access the resources, you should implement the client credentials grant.
  • Client type: Depending on whether or not the client is capable of keeping a secret will depend on which grant is most suitable for the client. For example, if the client is a web app that has a server-side component you should implement the authorization code grant.

With a solid foundation and a good understanding of different OAuth 2.0 grant types, you should have a clear idea of what is most suitable for you and your business. Picking the right grant type will help you keep your app secure when delivering a smooth user experience, too.

See how Kinde compares to other authentication providers.

OAuth 2.0 grant types explained (2024)

FAQs

What is OAuth 2.0 grant_type explained? ›

What is an OAuth 2.0 Grant Type? In OAuth 2.0, the term “grant type” refers to the way an application gets an access token. OAuth 2.0 defines several grant types, including the authorization code flow. OAuth 2.0 extensions can also define new grant types.

Which OAuth grant type is appropriate? ›

Authorization Code Grant

Use Case: Best for web and mobile applications where the client can securely store the client secret. The Authorization Code Grant is the most common and secure OAuth grant type. It involves an intermediate authorization code, which the application exchanges for an access token.

What is the difference between response_type and grant_type? ›

response_type is used against authorization endpoint. This parameter defines what authorization response must contain in its response. For example, code when using authorization code grant (similarly authorization code flow in OpenID Connect). grant_type on the other hand is used against the token endpoint.

What is the difference between flow and grant type? ›

1 Answer. The flow is more generic and refers to the whole protocol that allows the access token issuance. The authorization grant refers only to the credentials used during the flow (authorization code, client credentials...).

What is the most common grant type? ›

The most popular type of grant is for Program support. Program grants provide funding for specific projects or programs. Generally, these are restricted grants, where recipients must only use funds for the exact purpose outlined in the grant proposal.

What is the implicit grant type in OAuth2? ›

The implicit grant flow makes use of redirect url for security. The redirect url is registered with the authorization server beforehand by a developer or admin, so the admin has control over where the access token is sent. You don't need refresh tokens.

What does grant type mean? ›

Application grant types (or flows) are methods through which applications can gain Access Tokens and by which you grant limited access to your resources to another entity without exposing credentials. The OAuth 2.0 protocol supports several types of grants, which allow different types of access.

Which grant types do not support refresh tokens? ›

The implicit grant does not support refresh tokens. Therefore, any application using the implicit grant will need to explicitly re-request authorization from the user when an access token expires. See Implicit Grant in the official OAuth 2.0 spec.

What is the difference between implicit and code flow in OAuth 2.0 authorization? ›

With the "Implicit" flow the client (likely a browser) will get a access token, after the Resource Owner (i.e. the user) gave access. With the "Authorization Code" flow however, the client (usually a web server) will only get an authorization code after the Resource Owner (i.e. the user) gave access.

What is OAuth 2.0 in simple terms? ›

OAuth 2.0, which stands for “Open Authorization”, is a standard designed to allow a website or application to access resources hosted by other web apps on behalf of a user.

Is OAuth 2.0 authentication or authorization? ›

OAuth is a specification for authorization

OAuth 2.0 is a specification for authorization, but NOT for authentication. RFC 6749, 3.1. Authorization Endpoint explicitly says as follows: The authorization endpoint is used to interact with the resource owner and obtain an authorization grant.

How does OAuth 2.0 work in the rest API? ›

OAuth 2.0 is a standard for implementing delegated authorization, and authorization is based on the access token required to access a resource. The access token can be issued for a given scope, which defines what the access token can do and what resources it can access.

What is the most secure grant type? ›

The Authorization Code grant type is the most frequently used grant type and the most secure. To get a token using this grant type, the following information needs to be specified in the HTTP request to the Provider: Client ID of the client application.

When to use OAuth grant type? ›

Tips for choosing the right OAuth grant type

A third-party client is one that you don't trust. Access token owner: If you're authorizing a machine to access resources and you won't require the permission of a user to access the resources, you should implement the client credentials grant.

What are the grant types in the OAuth 2.0 framework? ›

  • OAuth 2.0 Clients. OAuth 2.0 Grant Types. Authorization Code Grant. Implicit Grant. Client Credentials Grant. Refresh Token Grant. Kerberos Grant. Mutual TLS Client Authentication and Certificate-Bound Access Tokens. ...
  • OpenID Connect OpenID Connect. OpenID Connect.

What is Grant_type in Keycloak? ›

The Client Credentials grant type is used by clients to obtain an access token outside of the context of a user. This is typically used by clients to access resources about themselves rather than to access a user's resources.

What is the bearer grant type? ›

The JWT Bearer grant type is used when the client wants to receive access tokens without transmitting sensitive information such as the client secret.

Top Articles
Upto Brain-Latest Science, Health, Technology News
Purchase Adjustment Amount Definition | Law Insider
Cranes For Sale in United States| IronPlanet
Printable Whoville Houses Clipart
Walgreens Pharmqcy
Euro (EUR), aktuální kurzy měn
What Auto Parts Stores Are Open
Best Cav Commanders Rok
Insidekp.kp.org Hrconnect
The Witcher 3 Wild Hunt: Map of important locations M19
Moparts Com Forum
Moonshiner Tyler Wood Net Worth
065106619
New Stores Coming To Canton Ohio 2022
Slope Tyrones Unblocked Games
Www Craigslist Milwaukee Wi
X-Chromosom: Aufbau und Funktion
Www Craigslist Com Bakersfield
Panolian Batesville Ms Obituaries 2022
Reviews over Supersaver - Opiness - Spreekt uit ervaring
Deshuesadero El Pulpo
Why Are Fuel Leaks A Problem Aceable
Greensboro sit-in (1960) | History, Summary, Impact, & Facts
Bra Size Calculator & Conversion Chart: Measure Bust & Convert Sizes
EVO Entertainment | Cinema. Bowling. Games.
Cal State Fullerton Titan Online
Calvin Coolidge: Life in Brief | Miller Center
APUSH Unit 6 Practice DBQ Prompt Answers & Feedback | AP US History Class Notes | Fiveable
Kids and Adult Dinosaur Costume
Storelink Afs
Roadtoutopiasweepstakes.con
The Hoplite Revolution and the Rise of the Polis
NIST Special Publication (SP) 800-37 Rev. 2 (Withdrawn), Risk Management Framework for Information Systems and Organizations: A System Life Cycle Approach for Security and Privacy
Tributes flow for Soundgarden singer Chris Cornell as cause of death revealed
Dreammarriage.com Login
Dadeclerk
How much does Painttool SAI costs?
Noaa Marine Weather Forecast By Zone
This 85-year-old mom co-signed her daughter's student loan years ago. Now she fears the lender may take her house
2023 Fantasy Football Draft Guide: Rankings, cheat sheets and analysis
Lcwc 911 Live Incident List Live Status
Isabella Duan Ahn Stanford
Is Ameriprise A Pyramid Scheme
What Is The Optavia Diet—And How Does It Work?
John Wick: Kapitel 4 (2023)
Bridgeport Police Blotter Today
Bank Of America Appointments Near Me
Model Center Jasmin
Mawal Gameroom Download
Epower Raley's
Palmyra Authentic Mediterranean Cuisine مطعم أبو سمرة
Ihop Deliver
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6207

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.