OAuth 2.0 Basics
Table of Contents + â
Youâve seen this button everywhere, right? You land on some new app, and instead of asking you to make a fresh account, it just says âLog in with Googleâ:
- You click it, a Google screen pops up, you say yes, and boom, youâre in.
- But hereâs the wild part. You never typed your Google password into that new app.
- And yet, somehow, the app now knows your name and email. How does that even work?
That magic button is powered by something called OAuth 2.0. So letâs slow down and see exactly whatâs going on behind it.
đŻ The Problem
Letâs picture a real situation. Say youâve got a photo printing app, and you want it to grab your photos straight from your Google account so you donât have to upload them one by one:
- The printing app needs to reach into your Google Photos and pull out your pictures.
- The easy-but-terrible way would be to just hand the app your Google email and password.
- But think about what that means. Now that app can read your Gmail, see your contacts, delete your stuff, change your password. It can do anything you can do.
Thatâs way too much power to give some random app just so it can print a few photos, right? So hereâs the real question this whole topic answers:
- How do you let App B use some of your data from App A?
- Without ever giving App B your password?
- And in a way where you can take that access back later if you change your mind?
đ What is OAuth 2.0
OAuth 2.0 is the standard way to solve exactly that problem. Letâs define it clearly:
- OAuth 2.0 is an authorization framework. An authorization framework is just an agreed-upon set of rules that lets one app get limited access to your account on another service.
- The key trick is this. Instead of giving the app your password, the app gets a token. A token is a short string that acts like a temporary pass, saying âthe owner allows this much access, for now.â
- So the app uses that token to do its job, and it never sees your actual password. Not even once.
Hereâs the one line to burn into your memory. OAuth is about authorization, not authentication:
- Authorization means deciding what someone is allowed to do. Like âthis app may read your photos.â
- Authentication means proving who you are. Like logging in to confirm youâre really you.
- OAuthâs main job is that first one, allowing access. Weâll come back to this difference later because it trips up almost everyone.
Authorization vs authentication
These two words sound alike but mean different things. Authentication answers âwho are you?â and authorization answers âwhat are you allowed to do?â OAuth 2.0 lives mostly in the authorization world. Thereâs a full breakdown in Authentication vs Authorization.
đ§Š The Players
OAuth has four roles in the story, and once you know whoâs who, the whole thing clicks. Letâs meet them using our photo printing example:
- Resource owner is you. Youâre the one who owns the data (your photos) and gets to say who can touch it.
- Client is the app that wants access. Here itâs the photo printing app. âClientâ just means the app making the request, nothing fancy.
- Authorization server is the one that checks with you and hands out tokens. For Google data, this is Googleâs login system.
- Resource server is where your actual data lives. Here itâs Google Photos, the place the client will call to fetch your pictures.
Hereâs the same thing laid out side by side so itâs easy to keep straight.
| Role | Who it is | In plain words |
|---|---|---|
| Resource owner | You | The person who owns the data and grants permission |
| Client | The photo printing app | The app that wants limited access to your data |
| Authorization server | Googleâs login | Asks you to approve, then issues the access token |
| Resource server | Google Photos | Holds your data and checks the token before giving it out |
âď¸ The Basic Flow
Now letâs walk the whole thing start to finish. Youâre on the photo printing app and you click âConnect Google Photos.â Hereâs what happens:
- You click the connect button on the client (the printing app).
- The app sends you over to the authorization server, which is Googleâs login page. This is called a redirect, meaning the app just points your browser somewhere else.
- Google shows you a screen that says something like âPhoto Printer wants to view your photos. Allow?â You read it and you approve.
- Google then issues an access token and hands it back to the app. An access token is that temporary pass we talked about, a short string the app shows to prove itâs allowed in.
- Now the app uses that token to call the resource server (Google Photos) and pull only your photos. Nothing else.
Two terms to lock down from that flow:
- An access token is the temporary key the app uses to make requests. It carries the permissions you approved, and it usually expires after a while.
- A scope is the specific permission being asked for, like âview photos.â Weâll dig into scopes next, since theyâre what keeps the access limited.
Hereâs the flow as a picture. Notice how the password never leaves Google.
Why this is safe
Look closely at the diagram. You type your password only on Googleâs own page, never on the appâs page. The app just walks away with a token that says âallowed to view photos.â Thatâs the whole point. The app gets a job done without ever holding the keys to your account.
đŻ Scopes
So how does Google know the app should only see photos and not your email? Thatâs what scopes are for. Letâs define it:
- A scope is one specific permission the app is asking for. Things like âread your emailâ or âview your photosâ or âsee your basic profile.â
- When the app sends you to the approval screen, it lists the exact scopes it wants. Thatâs why the screen says âwants to view your photosâ and not just âwants access.â
- The access token you get back is stamped with only those scopes. So the app can do those things and literally nothing more.
Why this matters so much:
- Scopes keep access narrow. The printing app asks for photos, so it gets photos, and it canât go poking around your inbox.
- You can see exactly what youâre agreeing to before you click approve. No surprises.
- It follows a good security habit called least privilege, which just means give an app the smallest amount of access it needs to do its job, and nothing extra.
đ OAuth vs Login
Okay, so if OAuth is about authorization, then whatâs actually happening when you âSign in with Googleâ to log into an app? Good question. Letâs untangle it:
- Plain OAuth 2.0 is about delegated access. âDelegatedâ means youâre handing off a slice of your permissions to an app. So OAuth gives the app a token to do things with your data.
- But logging in is a different need. The app doesnât want to do things, it just wants to know who you are so it can let you into your account.
- For that, thereâs a layer built on top of OAuth called OpenID Connect, often shortened to OIDC. OpenID Connect adds identity on top of OAuth, so the app gets a verified answer to âwho is this person?â
So the short version is this:
- OAuth 2.0 by itself handles authorization, letting an app access your data.
- OpenID Connect sits on top and handles authentication, telling the app who you are.
- âSign in with Googleâ uses both together. Thatâs why it can log you in and know your name and email.
â ď¸ Common Mistakes and Misconceptions
A few ideas trip people up constantly. Letâs clear them out one by one:
- âOAuth is authentication.â Not really. OAuth 2.0 is about authorization, deciding what an app may access. The login part comes from OpenID Connect layered on top, not from OAuth itself.
- âThe app sees your password.â It never does. You type your password only on the authorization serverâs own page (like Googleâs). The app only ever gets a token.
- âTokens never expire.â They do, and thatâs a good thing. Access tokens usually expire after a short time, so even if one leaks, it stops working soon. Thatâs a feature, not a bug.
đ ď¸ Design Challenge
Try this on your own to test yourself.
Imagine youâre building a calendar app, and you want it to read events from a userâs Google Calendar so it can show them in one place. Walk through the OAuth flow for it:
- Who is the resource owner, the client, the authorization server, and the resource server here?
- What single scope would you ask for, and why just that one?
- Where exactly does the user type their password, and where do they not?
Write down your answers, then check them against the four roles and the flow above. If you can narrate this cleanly, youâve got OAuth.
đ§Š What Youâve Learned
You can now explain how that âLog in with Googleâ button actually works. Hereâs what youâve picked up.
- â OAuth 2.0 lets an app get limited access to your data on another service, without ever seeing your password.
- â The app gets an access token instead, a temporary pass that carries only the permissions you approved.
- â There are four roles: resource owner (you), client (the app), authorization server (issues tokens), and resource server (holds your data).
- â Scopes keep access narrow, so the app can only do the specific things you agreed to.
- â OAuth handles authorization, not authentication. OpenID Connect adds login on top.
- â Tokens expire and can be revoked, which limits the damage if one ever leaks.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
What problem does OAuth 2.0 solve?
Why: OAuth lets App B use some of your data from App A through a token, so you never hand over your password.
- 2
In OAuth, who is the resource owner?
Why: The resource owner is you; the client is the app, the authorization server issues tokens, and the resource server holds your data.
- 3
What does a scope do in OAuth?
Why: A scope is one specific permission the app asks for, so the token grants only that and nothing more.
- 4
Is OAuth 2.0 about authentication or authorization?
Why: OAuth handles authorization; 'Sign in with Google' adds OpenID Connect on top to handle the authentication part.
đ Whatâs Next?
Youâve got the foundation now. Next, go deeper into the ideas OAuth builds on.
- Authentication vs Authorization clears up the difference between proving who you are and what youâre allowed to do.
- API Security shows how tokens, keys, and access controls keep your APIs safe in the real world.
Get those down, and youâll have a solid grip on how modern apps share data safely without passing passwords around.