Different types of Authorization Grants and when to use them


Hello there,

Hope you are doing good.

Token based Authentication is one of the most popular and widely used authentication and identity management systems used across the world.

It is simple, easy to integrate and makes user experience better.

Applications can decouple User Identity and Authentication layer to an externalized Authorization Server layer and delegate authentication to this server.

You will only enter credentials at a centralized Identity Provider site and the application accesses your profile or identity using a token that this Identity Provider issues to this application.

This token is application specific and one application cannot use this token from another application. This way you can ensure that your information is not being misused.

An Authorization Server or Secure Token Server is a component that is responsible for managing and issuing tokens to registered clients.

Identity Providers such as Google, Microsoft, Facebook etc. have their own Authorization servers that they have externalized for third-party app integrations.

You register your application as a client to the Authorization Server with details about what information your application expects after authentication (such as email, profile, etc.) what scopes it may ask for and the domain from which the request will be made.

On every request from this application, the Authorization Server validates these details and returns with the requested information.

Authorization Grant Types define the different ways in which a client application can request for tokens from an Authorization Server depending on the scenarios and use cases.

The following are the popular Authorization Grant Types -

Implicit: Used to retrieve tokens via browser. Client redirects the user to the authorization server where after consent the Server redirects back with the token without any back end call. This is not recommended. Authorization Code flow must be used instead.

Authorization Code: Used to retrieve tokens in the back channel instead of front-end via browser, now recommended for all client side applications. Client redirects the user to the Authorization Server, the user is authenticated and provides consent. The Authorization server redirects back to the client with an authorization code, followed by an API call to get the required token information.

Client Credentials: Used in App to App request scenarios, where an Application requests for Tokens from an Authorization Server with its Client Id and Client Secret. The Authorization Server returns back with Tokens. No consent or redirection is present and requests happen via back end API calls.

Resource Owner Password Credentials: Used in cases where an application impersonates a user and requests for tokens based on a username password combination.

Hybrid: Hybrid is an authentication flow where we combine two or more authentication flows to get multiple token results. possible examples are — authorization code with access token, authorization code with id token, access token and id token etc.

Refresh Token: This is used when clients need to request a new access token using a refresh token, which was obtained during the initial authentication.

You can find out more resources about Authorization and Implementing these Grant Types in ASP.NET Core here — https://referbruv.com/categories/identityserver4/

Follow on Medium - https://isriramkumarm.medium.com/different-types-of-authorization-grants-and-when-to-use-them-9c994a643770

I hope this content is useful to you. Subscribe to my Newsletter on Substack - https://codingramen.substack.com/

Have a great week.

Cheers

Ram

Hi there, I’m Ram

If you're starting in software engineering or an experienced professional, I post informative content around stuff I work with - Full Stack Development. Subscribe to my newsletter to receive my latest posts.

Read more from Hi there, I’m Ram

Hello there, Hope you are doing good. In this week's newsletter, I want to introduce you to the third principle of the SOLID principles: five principles describing few fundamental rules for developing arguably ideal software components which are scalable, extensible, robust and flexible - the Liskov Substitution Principle. This principle can be termed as one of the basic foundations of the Object Oriented Design languages which talks mainly about substitutions and inheritance. The principle...

Hello there, Hope you are doing good. In this week's newsletter I want to introduce you to one of the most efficient internal sorting algorithm, and discuss how to implement it - Quicksort algorithm step by step with an example and analyze time complexity. Quick Sort is an internal sorting technique which can be used to arrange a given set of unordered dataset into required order. It is the most efficient internal sorting technique, which doesn’t use any auxiliary memory (or additional space...

Hello there, Hope you are doing good. In this week's newsletter, I want to introduce you to the fourth principle of the SOLID principles - Interface Segregation. In the early stages of application development, it’s common to place all logic into a single class. As the application grows, these classes become bloated or “fat” with unrelated responsibilities. Later, when we try to extract interfaces from these classes for modularity or extension, we may end up with interfaces containing many...