What Is OAuth (Open Authorization)? How It Works, Flows and Tokens
.webp)
OAuth stands for Open Authorization. This open standard permits one application to access data in another application without ever exposing your password. Your approval sets permissions, and a temporary access token grants access rather than credentials.
It comes up when a calendar application wants to sync with Google Calendar or when you sign in with GitHub. Current OAuth is known as OAuth 2.0, and the older OAuth 1.0 is obsolete. The proposed next-generation OAuth 2.1 integrates years of security patches into a unified specification but remains an IETF draft.
.webp)
How does OAuth work?
Most apps today use the Authorization Code flow with PKCE. Here's what happens when, say, a photo editor wants your Google Photos:
- The app asks. It sends you to Google's authorization server with the access it wants (its scopes) and a redirect URL.
- You log in and approve. Google checks who you are and shows a consent screen listing exactly what the app will get.
- The app gets a code. Google redirects you back to the app with a short-lived, one-time authorization code.
- The app swaps the code for tokens. Behind the scenes it sends the code, plus a PKCE verifier or client secret, to Google's token endpoint.
- The app calls the API. It sends the access token with each request, and Google Photos checks the token and its scopes before returning anything.
.webp)
Key roles and tokens in OAuth
- Resource owner: you, the person whose data it is.
- Client: the app that wants access. It's registered with a client ID, and a client secret if it runs on a server.
- Authorization server: logs you in, shows the consent screen and issues tokens.
- Resource server: the API that holds your data and checks every token.
- Access token: a short-lived key the app sends with API calls, usually as a Bearer token. It can be an opaque string or a signed JWT.
- Refresh token: a longer-lived token used to get new access tokens without asking you to log in again.
- Scopes: the specific permissions granted, such as read-only access to your calendar.
OAuth flows and when to use each
OAuth vs OpenID Connect, SAML and API keys
OAuth is about permission, not identity. When an app needs to know who you are, it uses OpenID Connect on top of OAuth, which adds an ID token with your profile details. Read more on how this applies to API authorization in a gateway.
OAuth and AI agents
AI agents are raising OAuth's stakes, not lowering them. The Model Context Protocol (MCP), which governs how agents access tools, employs OAuth 2.1 for remote MCP servers: the MCP server acts as the resource server, while the client obtains access via the authorization code flow with proof key for code exchange (PKCE) prior to using any tools.
That scenario holds water for one operator and one resource server. It falls apart under the weight of multiple operators and numerous resource servers, such as GitHub, Slack, Jira, and so forth, each with its own tokens, scopes, refresh intervals, and associated variables.
TrueFoundry's MCP Gateway takes that work off each agent. It runs the OAuth flow once per user for tools like GitHub and Slack, uses client credentials for shared services, stores tokens encrypted, refreshes them before they expire, and never hands the downstream token to the agent. Here's a deeper look at OAuth token management for MCP and MCP server authentication.

Govern, Deploy and Trace AI in Your Own Infrastructure
Frequently Asked Questions
What is the main purpose of OAuth?
The main purpose of OAuth is to enable secure, delegated access to user data without sharing passwords. It allows users to grant limited permissions to applications, ensuring controlled access while protecting sensitive credentials and maintaining user trust across services.
Does Gmail use OAuth?
Yes, Gmail uses OAuth 2.0 the current standard version of OAuth to allow third-party apps to access emails securely. When you grant permission, Google issues an access token, enabling the app to interact with your Gmail data without exposing your login credentials or password.
Is OAuth better than an API key?
OAuth and API keys serve different purposes. OAuth is better for user-based access with granular permissions and consent. API keys are simpler and used for application-level access but offer less security and control compared to OAuth’s token-based authorization approach.

















