What Is OAuth? "Sign in with Google" and Delegated Access Explained
OAuth lets an app access another service for a user without their password. How it works, scopes, tokens, OpenID Connect and what to ask your AI builder.
Mythex Team · · 5 min read
OAuth is an open standard that lets a user give one app limited access to their account on another service, without handing over their password. When you click "Connect Google Calendar" and see a screen asking "Allow this app to see your events?", that's OAuth. The app gets a token for exactly what you approved, which you can revoke at any time. The same machinery, with an extra layer called OpenID Connect, powers "Sign in with Google" and similar buttons.
Why OAuth matters when you build with AI
OAuth shows up in two common situations when you build an app:
- Social login. You want your users to "Sign in with Google" (or Apple, Microsoft, GitHub) instead of creating another password. See how to add login to your app.
- Connecting to users' accounts on other services. Your app needs to read a user's calendar, post to their social account, pull files from their cloud drive or sync their accounting data.
In both cases your AI builder can write the code, but some steps only you can do: creating a developer app with the provider, getting a client ID and client secret, registering callback URLs and, for some permissions, passing the provider's review. Knowing how OAuth works makes those steps — and the errors they produce — much less mysterious. For the bigger picture of login, see what authentication is.
An everyday analogy
Think of a hotel key card. At check-in, the front desk confirms who you are, then gives you a card that opens your room and the gym — not the other rooms, not the staff areas — and stops working at checkout. The card doesn't contain your passport. If you lose it, the desk cancels it and issues a new one.
- The front desk is the authorization server (Google's sign-in page).
- Your ID check is you logging in to Google.
- The key card is the access token.
- "Room and gym only" are the scopes you approved.
- Checkout is the token expiring, or you revoking access.
The app you're using never sees your Google password, only the key card.
How OAuth works, step by step
The most common flow for web apps is the authorization code flow. Here's what happens when a user connects their Google Calendar to a scheduling app:
- Click. The user clicks "Connect Google Calendar."
- Redirect to the provider. The app sends the browser to Google with its client ID, the scopes it wants (read calendar events) and the redirect URI where Google should send the user back.
- Log in and consent. The user signs in to Google (if not already) and sees a consent screen listing what the app is asking for. They click Allow.
- Back with a code. Google redirects the browser to the app's redirect URI with a short-lived, one-time authorization code.
- Exchange on the server. The app's server sends that code, plus its client secret, directly to Google and receives an access token (and often a refresh token).
- Use the API. The server calls Google Calendar's API with the access token and gets the user's events.
The callback in step 4 looks something like this:
https://yourapp.com/auth/google/callback?code=4/0Adeu5B...&state=x7Kq9
And the token response in step 5 is JSON like:
{
"access_token": "ya29.a0Af...",
"expires_in": 3599,
"refresh_token": "1//0gL...",
"scope": "https://www.googleapis.com/auth/calendar.readonly",
"token_type": "Bearer"
}
The important design point: the token exchange happens server-to-server, so the client secret and tokens never need to pass through the browser.
OAuth vs OpenID Connect vs your own login
| What it answers | Example | |
|---|---|---|
| OAuth 2.0 | "What is this app allowed to do on the user's behalf?" (authorization) | Read a user's calendar |
| OpenID Connect (OIDC) | "Who is this user?" (authentication), built on OAuth | "Sign in with Google" returning a verified email |
| Your own login | "Is this the right password for this account?" | Email and password stored (hashed) in your database |
Many apps combine them: email-and-password login, plus "Sign in with Google" via OIDC, plus separate OAuth connections to other services.
Key terms
| Term | Meaning |
|---|---|
| Provider / authorization server | The service the user logs in to and grants access at — Google, Microsoft, GitHub. |
| Client | Your app, as registered with the provider. |
| Client ID | Your app's public identifier with the provider. |
| Client secret | Your app's private password with the provider. Server-only. |
| Scope | A specific permission, like "read calendar" or "view email address." |
| Consent screen | The page where the user sees and approves the requested scopes. |
| Redirect URI / callback URL | Where the provider sends the user back. Must be registered in advance and match exactly. |
| Access token | Short-lived credential for calling the API. |
| Refresh token | Longer-lived credential for getting new access tokens. Store it like a password. |
| ID token | In OIDC, a signed token describing who the user is. |
| PKCE | An extra check ("proof key") that stops intercepted codes being used. Recommended for all clients. |
| state | A random value that protects the flow against forged requests. |
Common misconceptions
- "OAuth is a login system." Plain OAuth grants access; OpenID Connect handles identity. Using a bare access token as proof of who someone is has caused real security bugs.
- "The app gets my password." It never does. That's the point.
- "Asking for more scopes is harmless." Users are warier of broad requests, and providers such as Google may require an app review for sensitive or restricted scopes. Ask only for what you need.
- "The client secret can go in the frontend." Anything in browser code is public. Keep it in server-side secrets.
- "It works in testing, so it'll work in production." Providers often limit unverified apps — for example, to listed test users — and the redirect URI for your live domain has to be registered separately.
- "Tokens last forever." Access tokens expire quickly, and users can revoke access. Your app has to handle both gracefully.
What to ask your AI builder
- "Add 'Sign in with Google' using OpenID Connect with a well-maintained auth library — don't hand-roll the OAuth flow."
- "Use the authorization code flow with PKCE and check the
stateparameter." - "Read the client ID and client secret from environment variables on the server."
- "Request only the scopes we need: read-only calendar access."
- "Tell me every redirect URL I need to register in the provider's console, for the preview, the published URL and my custom domain."
- "Store refresh tokens encrypted in the database, and handle expired or revoked tokens by asking the user to reconnect."
- "Let users disconnect the integration from their settings page."
OAuth and Mythex
Mythex doesn't have built-in end-user login for the apps you build; its docs describe a bring-your-own approach — you choose an auth library or hosted provider, store its keys as project secrets, and the agent writes the code. The add authentication recipe has a starter prompt for this. You'll also meet OAuth in Mythex itself: you can sign up with Google, connecting GitHub for repo sync uses GitHub OAuth, and AI clients that connect to Mythex over MCP go through an OAuth consent page. For more, see what authentication is and what two-factor authentication is.
Questions
What is OAuth in simple terms?
OAuth is a standard way for a user to let one app access their account on another service — like letting a scheduling app read their Google Calendar — without giving that app their password. The user approves specific permissions, and the app receives a token it can use for just those.
Is OAuth the same as "Sign in with Google"?
"Sign in with Google" is built on OAuth 2.0 plus OpenID Connect, a layer on top of OAuth that adds a standard way to tell the app who the user is. OAuth by itself is about granting access; OpenID Connect is what turns it into a login.
What is an OAuth access token?
An access token is a credential the app sends to a service's API to prove it has been granted access. It is usually short-lived and limited to the permissions (scopes) the user approved. A refresh token, if issued, lets the app get new access tokens without asking the user again.
What does redirect_uri_mismatch mean?
It means the callback URL your app sent during sign-in doesn't exactly match one registered in the provider's developer console. Add the exact URL — including https, domain, path and any trailing slash — for every address your app runs on.
Is OAuth secure?
OAuth 2.0 is widely used and secure when implemented correctly: using the authorization code flow with PKCE, exact redirect URLs, the state parameter, and keeping the client secret and tokens on the server. Most problems come from implementation shortcuts, which is why using a well-maintained library is recommended.