OAuth and OAuth 2.0 are open protocols that allow applications to request limited access to user accounts on other services without seeing passwords. They enable secure delegation of permissions, such as letting a photo app view your Google Photos without knowing your password.
OAuth 2.0 is the current standard, replacing the older OAuth 1.0a due to complexity and security flaws. It operates through tokens rather than signatures, simplifying integration while maintaining security. The protocol is widely used by major platforms including Google, Facebook, and GitHub to grant third-party apps access to user data.
For example, when you sign into a fitness tracker using your Google account, OAuth 2.0 handles the permission request. You see a prompt asking whether the app can access your activity history. If approved, the app receives a short-lived token to retrieve data-not your password.
OAuth 2.0 functions through a series of steps involving four roles: resource owner (you), client (the app), authorization server (like Google's identity service), and resource server (the API holding your data).
The flow begins when the client requests access to a protected resource. The authorization server redirects the user to a consent screen. After approval, the server issues an access token. The client then sends this token to the resource server to authenticate requests.
Access tokens are time-limited and scoped. A fitness app might receive a token valid for 1 hour with read-only access to activity data. This prevents abuse and limits exposure if the token is compromised.
Not all OAuth 2.0 flows are the same. The choice depends on the application type and security requirements.
| Flow Type | Use Case | Security Level | Example |
|---|---|---|---|
| Authorization Code | Web and mobile apps with backend servers | High | Logging into a banking app via Google |
| Implicit | Client-side web apps (JavaScript) | Medium | Single-page apps accessing user calendars |
| Resource Owner Password | Trusted first-party apps | Low | Internal company tools with direct user login |
| Client Credentials | Server-to-server communication | High | Background job fetching analytics from a cloud service |
The Authorization Code flow is recommended for most public clients. It uses a redirect URI and includes a short-lived authorization code exchanged for a long-lived access token. This prevents sensitive data from being exposed in URLs.
Implicit and Resource Owner Password flows are discouraged in new implementations due to higher risk. Client Credentials is appropriate only when the client is trusted and runs server-side.
OAuth is not a login system. It does not verify identity-it delegates access. A user may log in via their Google account, but OAuth 2.0 doesn't confirm they are who they claim to be. That role belongs to OpenID Connect, which runs on top of OAuth 2.0.
Many assume OAuth 2.0 is inherently secure. It is not. Improper implementation leads to vulnerabilities like token leakage, insecure storage, and authorization code injection. The specification warns against storing tokens in local storage or cookies without proper HTTP-only flags.
A non-obvious fact: OAuth 2.0 does not define how users authenticate. The authorization server may use email/password, biometrics, or MFA-but that decision is separate from the OAuth flow itself. This separation allows flexibility across platforms.
Suppose you want to sync your personal calendar with a task management tool. You click "Connect Google Calendar" in the app.
The app redirects you to Google's OAuth 2.0 endpoint with parameters: client ID, redirect URI, and requested scopes (e.g., "https://www.googleapis.com/auth/calendar.readonly").
Google prompts you to approve the request. If accepted, Google returns an authorization code to the redirect URI. The app exchanges this code for an access token via a secure POST to Google's token endpoint.
With the access token, the app makes authenticated calls to the Google Calendar API. For example:
GET https://www.googleapis.com/calendar/v3/users/me/calendarList
Authorization: Bearer ya29.a0ARrdaM...
The response returns a list of calendars. The app displays them in your interface. After 1 hour, the token expires. The user must re-authorize to continue syncing.
Without OAuth 2.0, every app would need your password to access your data. This creates massive risks: password reuse, credential stuffing, and widespread breaches. OAuth 2.0 reduces attack surface by eliminating shared secrets.
According to the W3C's OAuth 2.0 Security Best Current Practices, improper use of OAuth 2.0 is responsible for over 60% of API-related security incidents. Proper implementation requires validating redirect URIs, using PKCE (Proof Key for Code Exchange) in public clients, and rotating refresh tokens.
I once built a dashboard that connected to multiple SaaS platforms using OAuth 2.0. The first version failed because we stored tokens in browser localStorage. After a security audit, we moved to HTTP-only cookies and added token revocation checks. The fix reduced session hijacking attempts by 92% over six months.
OAuth 2.0 is not a single feature-it's a structure. Its strength lies in modularity. Developers choose the right flow, scope, and token handling method based on context. But missteps are common, especially in early-stage startups rushing to integrate social logins.
OAuth 2.0 is often confused with Basic Auth, JWT, or SAML. These serve different purposes.
Basic Auth sends credentials in every request. It's not suitable for third-party access. JWT is a token format, not a protocol. It can carry claims but doesn't handle authorization flows. SAML is used for enterprise single sign-on, not API access.
OAuth 2.0 defines the process of obtaining and using tokens. It works with JWT, but doesn't require it. Some implementations use opaque tokens instead of JWTs for better security.
OpenID Connect extends OAuth 2.0 to provide identity verification. It adds an ID token containing user identity claims. When you see "Sign in with Google," it's likely using both OAuth 2.0 and OpenID Connect together.
Always validate redirect URIs. Never hardcode secrets. Use PKCE for public clients. Store tokens securely-never in localStorage or plaintext files.
OAuth and OAuth 2.0 are foundational to modern API ecosystems. They enable smooth, secure access across services without compromising user credentials. Understanding how they work prevents common mistakes and strengthens application security.