03. Understanding OAuth 2.0: Flows, Standards, and Security Best Practices

 

Understanding OAuth 2.0: Flows, Standards, and Security Best Practices


Core OAuth 2.0 Specification

This RFC describes the base OAuth 2.0 protocol and includes: https://datatracker.ietf.org/doc/html/rfc6749

 

Authorization Grant

An authorization grant is a credential representing the resource owner's authorization (to access its protected resources) used by the client to obtain an access token.  This specification defines four grant types

authorization code, implicit, resource owner password, credentials, and client credentials as well as an extensibility mechanism for defining additional types.

 

1. Authorization Flows (Grant Types) 

These define how a client gets an access token:

  •  Authorization Code Grant (most secure, used with server-side apps)
  •  Implicit Grant (now discouraged, used with SPAs)
  •  Resource Owner Password Credentials Grant (discouraged)
  •  Client Credentials Grant (machine-to-machine)

 

 2. Roles 

  •  Resource Owner (the user)
  •  Client (your app)
  •  Authorization Server (e.g., Google, Cognito)
  •  Resource Server (API/resource your app accesses)

 

 3. Token Types 

  •  Access Token (used to access protected resources)
  •  Refresh Token (used to get a new access token)

 

01. Authorization Code Grant (most secure, used with server-side apps)

  1. User clicks "Login with Google" on your app.
  2. Browser is redirected to Google login screen.
  3. User logs in → Google sends an authorization code to your app.
  4. Your app sends that code to Google to get an access token.
  5. Your app now uses the access token to call Google APIs.

 

 


 

02. Implicit Grant (now discouraged, used with SPAs)

The implicit grant is a simplified authorization code flow optimized for clients implemented in a browser using a scripting language such as JavaScript.  In the implicit flow, instead of issuing the client an authorization code, the client is issued an access token directly.

  


 

03. Resource Owner Password Credentials Grant (discouraged)

  1. User enters username and password in your app.
  2. App sends those credentials to the auth server.
  3. If correct, it returns an access token.

  


 04. Client Credentials Grant (machine-to-machine)

  1. App authenticates itself with client ID and secret.
  2.  Sends a request to the auth server.
  3. Gets an access token.
  4. Uses the token to call a protected API.



Comments

Popular posts from this blog

Database - Topics

02. Spring – Creating spring project clone it with GIT step by step.

01. Steps in SQL Query Execution (MySQL)