OAuth 2.0 Explained
Understand OAuth 2.0, authorization flows, access tokens, refresh tokens and how applications securely access protected resources.
OAuth 2.0 is an authorization framework that allows applications to access protected resources on behalf of a user without requiring the user's password. Instead of sharing credentials directly with third-party applications, OAuth uses access tokens that grant limited permissions for a specific period of time.
Today, OAuth 2.0 powers authentication and authorization for countless services including Google, Microsoft, GitHub, Facebook and many enterprise APIs. It enables secure integrations between applications while giving users control over what information they choose to share.
What Is OAuth 2.0?
OAuth 2.0 is an authorization framework—not an authentication protocol. Its primary purpose is to allow an application (the client) to obtain permission to access resources hosted by another service (the resource server) without exposing the user's login credentials.
Authentication vs Authorization
One of the most common sources of confusion is the difference between authentication and authorization. OAuth focuses on authorization, while authentication is often handled by protocols such as OpenID Connect, which builds on top of OAuth 2.0.
| Concept | Purpose |
|---|---|
| Authentication | Verifies who the user is |
| Authorization | Determines what the application may access |
Why OAuth 2.0 Is Important
Without OAuth, users would need to provide their passwords directly to every third-party application they wanted to use. OAuth eliminates this security risk by allowing trusted authorization servers to issue temporary access tokens with limited permissions.
- Protects user credentials.
- Grants limited access permissions.
- Supports temporary access tokens.
- Allows users to revoke access.
- Enables secure third-party integrations.
OAuth Roles
OAuth defines several participants that work together during the authorization process.
| Role | Description |
|---|---|
| Resource Owner | The user who owns the protected data |
| Client | The application requesting access |
| Authorization Server | Issues access tokens after user approval |
| Resource Server | Hosts the protected API or resources |
How OAuth 2.0 Works
The user is redirected to the authorization server, signs in if necessary and grants permission to the client application. The authorization server then issues an access token that the client includes in future API requests.
User
↓
Authorization Server
↓
Access Token Issued
↓
Client Calls API
↓
Resource ServerWhat Is an Access Token?
An access token is a temporary credential that authorizes API requests. It usually has a limited lifetime and may contain information about the permissions (scopes) granted to the client application.
Common OAuth Use Cases
- Sign in with Google or Microsoft.
- Cloud storage integrations.
- Social media APIs.
- Enterprise APIs.
- Mobile applications.
- Third-party SaaS integrations.
OAuth 2.0 Authorization Flows
OAuth 2.0 defines several authorization flows, also called grant types, designed for different kinds of applications. Each flow specifies how a client obtains an access token while balancing usability and security.
| Flow | Typical Use Case |
|---|---|
| Authorization Code | Web applications |
| Authorization Code with PKCE | Mobile and SPA applications |
| Client Credentials | Server-to-server communication |
| Device Authorization | Smart TVs and devices with limited input |
Authorization Code Flow
The Authorization Code flow is the most widely used OAuth flow for web applications. After the user grants permission, the client receives an authorization code, which is exchanged for an access token through a secure back-channel request to the authorization server.
PKCE
Proof Key for Code Exchange (PKCE) extends the Authorization Code flow by protecting public clients that cannot safely store a client secret. PKCE prevents attackers from intercepting authorization codes and exchanging them for access tokens.
Client Credentials Flow
The Client Credentials flow is intended for machine-to-machine communication. Since no user is involved, the client authenticates directly with the authorization server and receives an access token representing the application itself.
Access Tokens vs Refresh Tokens
Access tokens are typically short-lived to reduce security risks. Refresh tokens allow an application to obtain new access tokens without requiring the user to sign in again, providing a better user experience while maintaining security.
| Token | Purpose |
|---|---|
| Access Token | Authorizes API requests |
| Refresh Token | Obtains new access tokens |
OAuth Scopes
Scopes define the permissions an application requests from the user. Instead of granting unrestricted access, users approve only the specific capabilities required by the application, such as reading profile information or accessing email.
openid profile email
read:users
write:filesOAuth and JWT
OAuth does not require access tokens to use any specific format. However, many authorization servers issue JSON Web Tokens (JWTs) because they can securely contain claims about the user, client and granted permissions. Other systems use opaque tokens that have no readable content and must be validated by the authorization server.
OAuth vs API Keys
API keys identify an application but generally do not represent a user's permissions. OAuth is designed for delegated authorization, allowing users to grant limited access to their resources without sharing passwords or long-term credentials.
Where OAuth 2.0 Is Commonly Used
- Single Sign-On (SSO).
- Cloud service integrations.
- Social login providers.
- Enterprise identity platforms.
- REST and GraphQL APIs.
- Mobile and desktop applications.
- Microservice architectures.
Common Mistakes
OAuth 2.0 is a flexible framework, but incorrect implementations can introduce security vulnerabilities. Many problems arise from misunderstanding the difference between authorization and authentication or from storing tokens insecurely.
- Confusing OAuth with authentication.
- Granting broader scopes than necessary.
- Storing access tokens in insecure locations.
- Using long-lived access tokens unnecessarily.
- Failing to validate redirect URIs.
- Sending OAuth tokens over unencrypted HTTP connections.
Best Practices
- Use the Authorization Code flow with PKCE for modern applications.
- Request only the minimum scopes required.
- Keep access tokens short-lived.
- Store refresh tokens securely.
- Always use HTTPS for OAuth communications.
- Validate redirect URIs and authorization responses carefully.
Frequently Asked Questions
Is OAuth 2.0 an authentication protocol?
No. OAuth 2.0 is an authorization framework that grants applications permission to access protected resources. Authentication is commonly provided by OpenID Connect (OIDC), which extends OAuth 2.0.
What is the difference between an access token and a refresh token?
An access token authorizes API requests and usually expires after a short time. A refresh token is used to obtain new access tokens without requiring the user to authorize the application again.
Does OAuth require JWT tokens?
No. OAuth is token-format agnostic. Many providers issue JWT access tokens, while others use opaque tokens that must be validated by the authorization server.
Why are OAuth scopes important?
Scopes limit what an application can access. Requesting only the permissions that are actually needed reduces security risks and gives users greater control over their data.
Can OAuth be used for server-to-server communication?
Yes. The Client Credentials flow allows one application to obtain an access token and communicate securely with another service without user involvement.
Helpful API Tools
A JWT Inspector decodes and displays JSON Web Tokens, a JWT Claims Viewer examines the claims stored within a JWT payload, a JWT Header Viewer shows token metadata such as the signing algorithm, an API Key Generator creates secure random API keys for applications that use key-based authentication, and an HTTP Request Builder helps construct and test authenticated API requests using OAuth access tokens.
Conclusion
OAuth 2.0 has become the industry standard for delegated authorization across web applications, mobile apps and APIs. By allowing users to grant limited access through temporary tokens instead of sharing passwords, it improves both security and usability. Understanding OAuth roles, authorization flows, scopes and token management enables developers to build secure integrations that protect user data while providing seamless access to modern online services.