OAuth 2.0 enables secure access to third-party APIs and applications without sharing passwords. Discover how the authorization protocol behind every "Sign in with Google" flow works, which grant types exist, and how to implement it securely.
OAuth (Open Authorization) is an open standard authorization protocol that allows applications to obtain limited access to user accounts on external services without knowing the user's password. OAuth 2.0, the current version published as RFC 6749, is supported by virtually every major platform including Google, Microsoft, GitHub, Facebook, and Apple. The protocol forms the foundation of every "Sign in with..." flow on the modern web and is extended by OpenID Connect for authentication. OAuth 2.1, currently in development, consolidates best practices and mandates PKCE for all client types.

OAuth (Open Authorization) is an open standard authorization protocol that allows applications to obtain limited access to user accounts on external services without knowing the user's password. OAuth 2.0, the current version published as RFC 6749, is supported by virtually every major platform including Google, Microsoft, GitHub, Facebook, and Apple. The protocol forms the foundation of every "Sign in with..." flow on the modern web and is extended by OpenID Connect for authentication. OAuth 2.1, currently in development, consolidates best practices and mandates PKCE for all client types.
OAuth 2.0 defines four roles: the Resource Owner (the user granting permission), the Client (the application requesting access), the Authorization Server (issues tokens after verification), and the Resource Server (protects data and validates tokens). The protocol supports multiple grant types for different scenarios. The Authorization Code flow is the most secure for web applications: the user is redirected to the authorization server, grants explicit permission via a consent screen, and the client receives a one-time authorization code that is exchanged server-side for an access token and optionally a refresh token. PKCE (Proof Key for Code Exchange, RFC 7636) adds a cryptographic challenge that prevents intercepted authorization codes from being misused, and is mandatory for public clients like mobile apps and Single Page Applications. The Client Credentials flow is designed for machine-to-machine communication without user interaction, such as backend services exchanging data. The Device Authorization Grant (RFC 8628) is built for devices without a browser, like smart TVs and IoT devices. Access tokens intentionally have a short lifespan (typically 15 to 60 minutes) and are refreshed via longer-lived refresh tokens stored securely server-side. Token rotation on each refresh prevents reuse of stolen refresh tokens. Scopes limit access rights to specific API resources: an application can request read-only access to a calendar without write permissions. OpenID Connect (OIDC) is an identity layer on top of OAuth 2.0 that adds user authentication via ID tokens in JWT format with claims like sub, email, and name. Token introspection (RFC 7662) and revocation endpoints (RFC 7009) provide management over issued tokens. DPoP (Demonstrating Proof of Possession) is a newer extension that binds tokens to a specific client, rendering stolen tokens useless.
MG Software implements OAuth 2.0 in virtually every application we build. We use Supabase Auth which supports OAuth providers like Google, Microsoft, and GitHub out of the box with PKCE as the default. For SaaS products, we implement "Login with Google/Microsoft" flows so users can securely sign in with their existing accounts without us ever storing passwords. For API integrations with external systems, we use the Client Credentials flow for secure server-to-server communication. Access tokens are always stored server-side in HttpOnly cookies, never in localStorage. We advise clients on the right OAuth flow for their specific use case and ensure scopes are as minimal as possible to respect the principle of least privilege. Our implementations always include refresh token rotation so stolen tokens can only be used once. For multi-tenant SaaS platforms, we configure tenant-specific OAuth providers so each organization can log in through their own Microsoft Entra ID or Google Workspace domain.
In a world where users maintain dozens of online accounts, password fatigue is a real problem. Password reuse remains one of the biggest security risks on the web. OAuth addresses this by letting users sign in to applications using their existing accounts at trusted providers like Google or Microsoft, without the application ever needing to store a password. For developers, this eliminates the complexity and risk of password management: no hashing, no reset flows, no credential storage. For businesses, this translates to higher conversion (less registration friction), stronger security, and compliance with regulations like GDPR. The standardized approach of OAuth also makes it possible to securely integrate with hundreds of external services and APIs.
A common mistake is using OAuth for authentication when it is an authorization protocol. OAuth tells you what a user is allowed to do, not who the user is. Use OpenID Connect for authentication on top of OAuth 2.0. Developers frequently store tokens insecurely in localStorage, which is vulnerable to XSS attacks. Access tokens belong in HttpOnly cookies with Secure and SameSite flags. Redirect URI validation is sometimes implemented sloppily, enabling open redirect attacks. Overly broad scopes are another risk: always request only the minimum required permissions. Finally, teams forget to implement refresh token rotation, allowing a leaked refresh token to be reused indefinitely. Another mistake is not implementing the state parameter, which prevents CSRF attacks by sending a random value that is validated at the callback. Teams also regularly forget to build token revocation for when a user logs out or deletes their account.
The same expertise you're reading about, we put to work for clients.
Discover what we can doWhat is JWT? - Explanation & Meaning
JWT securely packages user data into a signed token for stateless API authentication without server sessions, which suits microservice architectures well.
Single Sign-On (SSO) Explained: Protocols, Identity Providers and Enterprise Security
Single Sign-On lets users access multiple applications with a single login through an Identity Provider. Learn how SAML 2.0, OAuth 2.0 and OIDC work, which IdP solutions are available, and why SSO is essential for enterprise security and compliance.
Auth0 vs Clerk: Enterprise Auth or Developer-First Identity?
Okta-backed RBAC with 7,000+ integrations or beautiful pre-built React auth components? Auth0 and Clerk target fundamentally different auth needs.
NextAuth vs Clerk: DIY Authentication or Drop-In Solution?
Free and open-source with full control or a managed service with pre-built UI? NextAuth and Clerk offer two paths to Next.js authentication.