API Directory โ€บ Guides โ€บ What Is OAuth? ('Login with Google' Explained)

What Is OAuth? ('Login with Google' Explained)

OAuth is how apps get permission to act on your behalf โ€” without you handing over your password. Here's the idea.

OAuth 2.0 is the standard way for an application to get permission to access a user’s data on another service — without the user handing over their password. When you click ‘Sign in with Google’ or let an app ‘connect to your GitHub’, that is OAuth.

The players

Resource ownerThe user who owns the data.
ClientYour application, which wants access.
Authorization serverWhere the user logs in and approves (e.g. accounts.google.com).
Resource serverThe API holding the data (e.g. the Google Calendar API).

The Authorization Code flow (the common one)

Public clients (single-page apps, mobile) add PKCE, a proof step that removes the need to ship a client secret.

Other grant types

Client CredentialsNo user involved — your app authenticates as itself for machine-to-machine access. Common for ‘app-only’ API tiers (e.g. Spotify catalogue search).
Device CodeFor TVs and CLIs: the device shows a code, the user enters it on their phone.
Refresh TokenExchanges a refresh token for a fresh access token.
Password (deprecated)User types their password into your app. Avoid — it defeats the point of OAuth.

Scopes

A scope is a named permission: read:user, repo, calendar.events.readonly. Request the minimum you need — users are more likely to approve, and a leaked token does less damage.

OAuth vs. OpenID Connect vs. API keys

Security essentials

FAQ

What is the difference between OAuth and an API key?

An API key identifies your application and is used for machine-to-machine calls. OAuth lets a user grant your app scoped, revocable access to their data on another service, without sharing their password.

What is a bearer token?

The access token OAuth issues. ‘Bearer’ means whoever holds it can use it — so it must be sent over HTTPS and kept secret. You send it as Authorization: Bearer <token>.

Why do access tokens expire so quickly?

To limit the damage if one leaks. Your app uses the longer-lived refresh token to get new access tokens without bothering the user again.

Is &lsquo;Sign in with Google&rsquo; the same as OAuth?

It uses OAuth 2.0 plus OpenID Connect. OAuth handles the permission grant; OIDC adds an identity token that tells your app who the user is.

Keep going

Try it on a real API

Browse all 196 free APIs โ†’

๐Ÿ”Œ Explore free public APIs

Hundreds of free APIs, searchable by category, with auth & CORS at a glance.

Browse the directory โ†’