Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

OAuth vs OIDC

Introduction

In the realm of Identity and Access Management (IAM), understanding the differences between OAuth and OpenID Connect (OIDC) is crucial for implementing secure authentication and authorization mechanisms.

Definitions

OAuth

OAuth 2.0 is an authorization framework that allows third-party applications to obtain limited access to user accounts on HTTP services, such as Facebook or Google.

OpenID Connect (OIDC)

OpenID Connect is an authentication layer built on top of OAuth 2.0. It provides a way to verify the identity of users based on the authentication performed by an authorization server.

OAuth

OAuth enables a user to grant a third-party application access to their resources without sharing credentials. It involves multiple roles:

  • Resource Owner
  • Client Application
  • Authorization Server
  • Resource Server

OAuth Workflow


        1. User initiates authentication.
        2. User is redirected to the Authorization Server.
        3. User grants permission to the Client Application.
        4. Authorization Server redirects back to the Client with authorization code.
        5. Client exchanges authorization code for an access token.
        6. Client uses access token to access resources on Resource Server.
    

OpenID Connect (OIDC)

OIDC extends OAuth 2.0 to provide user authentication. The key component is the ID Token, which is a JWT (JSON Web Token) that contains user information.

OIDC Workflow


        1. User initiates authentication.
        2. User is redirected to the OIDC Provider.
        3. User logs in and grants permission.
        4. OIDC Provider redirects back to the Client with an ID Token.
        5. Client verifies the ID Token and obtains user information.
        6. Client can now authenticate the user.
    

Key Differences

OIDC is built on top of OAuth 2.0, adding authentication features.
  • OAuth is for authorization; OIDC is for authentication.
  • OIDC uses ID tokens; OAuth does not.
  • OIDC provides user information directly; OAuth requires additional API calls.

Best Practices

When implementing OAuth and OIDC, consider the following:

  • Always use HTTPS to protect tokens.
  • Implement token expiration and rotation policies.
  • Use scopes to limit access to user data.
  • Validate ID Tokens to ensure authenticity.

FAQ

What is the main purpose of OAuth?

OAuth is primarily used for delegated authorization, allowing third-party services to access user information without sharing passwords.

Can OIDC be used without OAuth?

No, OIDC is built on top of OAuth 2.0 and requires it for its functionality.

What is an ID Token?

An ID Token is a JSON Web Token (JWT) that contains information about the user, issued by the Identity Provider during the authentication process.