Oauth2: Buzzwords Explained

Harsh Mighlani
6 min readMar 13, 2023

OAuth2 (Open Authorization 2.0) is an authorization framework that allows third-party applications to access user resources without requiring the user to share their credentials, such as username and password, with the third-party application. OAuth2 operates by granting access tokens to third-party applications, which can then be used to access user resources, such as data stored on social media platforms or cloud storage services. OAuth2 has become a popular authorization framework and is widely used by many web applications, social media platforms, and cloud services.

OAuth2 Components

OAuth2 has below components that work together to grant access to user resources:

  1. Resource Owner: The resource owner is the user who owns the resource, such as a social media account or a cloud storage account.
  2. Client: The client is the third-party application that wants to access the user’s resources.
  3. Authorization Server: The authorization server is responsible for authenticating the user, obtaining their consent, and issuing access tokens to the client.
  4. Resource Server: The resource server is the server that hosts the user’s resources, such as a social media platform or a cloud storage service.
  5. Access Token: An access token is a string of characters that allows the client to access the protected resources on behalf of the resource owner. It is issued by the authorization server after the resource owner grants permission to the client.
  6. Scope: A scope is a parameter used to specify the type of access requested by the client. It defines the specific resources or actions the client is authorized to access.
  7. Refresh Token: A refresh token is a token that is issued alongside an access token and can be used to obtain a new access token when the original token expires. This allows the client to maintain access to the protected resources without requiring the resource owner to re-authenticate.

OAuth2 Advantages

OAuth2 provides several advantages over traditional authentication methods, such as username and password authentication:

OAuth2 (Open Authorization 2.0) is an authorization framework that enables third-party applications to access user resources without requiring the user to share their credentials (such as username and password) with the third-party application.

OAuth2 operates by granting access tokens to third-party applications, which can then be used to access user resources, such as data stored on social media platforms or cloud storage services. The access tokens are issued by the authorization server, which acts as an intermediary between the user, the third-party application, and the resource server.

OAuth2 defines several grant types, including:

  1. Authorization Code: This grant type is used when the client (third-party application) is capable of keeping the client secret confidential. It involves exchanging an authorization code for an access token.
  2. Implicit: This grant type is used when the client is incapable of keeping the client secret confidential. It involves exchanging an access token directly for the authorization grant.
  3. Resource Owner Password Credentials: This grant type is used when the resource owner (user) has a trusted relationship with the client, such as a native mobile application.
  4. Client Credentials: This grant type is used when the client is requesting access to protected resources under its control.

OAuth2 Authorization Code grant type is one of the most widely used grant types of OAuth2. It is used when the client (third-party application) is capable of keeping the client secret confidential.

Here is how the OAuth2 Authorization Code flow works:

  1. The user initiates the authorization process by clicking on a login button on the client application.
  2. The client application redirects the user to the authorization server, where the user is prompted to enter their credentials.
  3. The authorization server verifies the user’s credentials and prompts the user to grant the client application access to their resources.
  4. If the user grants permission, the authorization server generates an authorization code and sends it back to the client application through a redirect URL.
  5. The client application then exchanges the authorization code for an access token by sending a request to the authorization server with the authorization code, client ID, and client secret.
  6. The authorization server verifies the authenticity of the client application, validates the authorization code, and issues an access token.
  7. The client application uses the access token to access the user’s resources on the resource server.

The OAuth2 Authorization Code grant type provides a secure way to obtain access tokens while keeping the client secret confidential. It is widely used in web applications, mobile applications, and APIs to access protected resources.

OpenID Connect

OpenID Connect is an identity layer protocol built on top of the OAuth 2.0 authorization framework. It provides a standardized way for authentication and authorization of users in web and mobile applications.

OpenID Connect allows users to authenticate using their existing accounts from providers such as Google, Facebook, and Microsoft. Instead of creating a new username and password for each application, users can use their existing credentials to access multiple applications.

OpenID Connect uses JSON Web Tokens (JWT) to transmit identity information securely between the identity provider and the application. The tokens contain information such as the user’s identity, authentication time, and any additional claims.

OpenID Connect has become a popular standard for modern authentication and authorization, and is used by many applications and services to provide a seamless and secure user experience.

Open ID Connect Use Cases:

  1. Single sign-on (SSO): OpenID Connect allows users to authenticate once and access multiple applications without having to enter their credentials multiple times. This can improve user experience and reduce friction for users.
  2. Standardized: OpenID Connect is a standardized protocol that provides a consistent way for authentication and authorization across different applications and identity providers.
  3. Security: OpenID Connect uses OAuth 2.0 and JWTs to transmit identity information securely between the identity provider and the application. This helps prevent unauthorized access to user data and helps ensure the confidentiality and integrity of user information.
  4. Federation: OpenID Connect allows for identity federation, which means that users can use their existing accounts from identity providers such as Google or Facebook to access other applications that support OpenID Connect. This can simplify the account creation process for users and reduce the burden on application developers.

PKCE stands for Proof Key for Code Exchange, which is an extension to the OAuth 2.0 protocol that adds an additional layer of security to the authorization code flow. The authorization code flow is one of the most commonly used flows in OAuth 2.0, and is used to obtain an access token from an authorization server.

PKCE is designed to protect against authorization code interception attacks, which can occur when an attacker intercepts the authorization code returned by the authorization server and uses it to obtain an access token for themselves. PKCE mitigates this risk by adding a unique secret value called a code verifier to the authorization request. The code verifier is used to derive a code challenge value, which is sent to the authorization server along with the authorization request. The authorization server then verifies the code challenge value before returning an authorization code to the client.

This helps ensure that the authorization code can only be used by the intended client, since the code challenge value can only be generated by the client that initiated the authorization request. PKCE is particularly useful for mobile and desktop applications, where it may be more difficult to securely store a client secret.

Overall, PKCE is an important security feature for OAuth 2.0, and is recommended for all public clients that use the authorization code flow.

DPoP stands for “Distributed Proof of Possession”, which is a protocol for providing proof of possession of a private key in OAuth 2.0 and OpenID Connect (OIDC) environments. It is designed to provide an additional layer of security for accessing protected resources, particularly in mobile and native applications.

In traditional OAuth 2.0 and OIDC environments, access tokens are used to access protected resources. However, access tokens can be stolen or intercepted by attackers, potentially leading to unauthorized access to protected resources. DPoP addresses this security concern by requiring the use of a private key to sign each request for a protected resource.

When a client wants to access a protected resource, it generates a DPoP token that includes a signature of the request and the client’s public key. The signature provides proof that the client has possession of the private key that corresponds to the public key included in the token. The DPoP token is then included in the request to the resource server, which can verify the signature and grant access to the protected resource if the DPoP token is valid.

DPoP is particularly useful for mobile and native applications where the client may not have a secure storage mechanism for storing a client secret. By requiring the use of a private key to sign requests, DPoP provides an additional layer of security for accessing protected resources in these environments.

--

--

Harsh Mighlani

AWS certified solutions architect | 12+ Years experienced | Loves Serverless & Containerization use cases.