Advanced Topic 39 of 51 Web Development
OAuth 2.0
Delegated authorization framework.
How it works
OAuth 2.0 is an authorization framework that lets an application obtain limited access to a user's resources on another service without receiving their password. Roles are the resource owner, client, authorization server and resource server. In the authorization code flow, the client redirects the user to the authorization server, receives a code and exchanges it for an access token, with PKCE protecting public clients; scopes limit what the token can do. OpenID Connect adds an identity layer on top.
Step-by-step walkthrough
- The app sends the user to the auth server.
- The user logs in and approves access.
- The server returns an authorization code.
- The app exchanges the code for an access token.
- The app calls the API with the token and never sees the password.
Where it is used
Sign in with Google or GitHub, granting apps access to calendars or repositories, and API access for third-party integrations use OAuth.
Common pitfall
Using the deprecated implicit flow, skipping the state parameter, loose redirect URI validation and storing tokens insecurely lead to token theft and CSRF. OAuth is for authorization, not authentication, unless OpenID Connect is used. Request minimal scopes, use PKCE and verify tokens' audience and issuer.
Where it fits in the course
OAuth 2.0 is topic 39 of 51 in Web Development, rated Advanced. It follows JWT. The next topic is CORS.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Web Development quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Web Development quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is OAuth 2.0?
Where do people use OAuth 2.0?
What is the most common mistake with OAuth 2.0?
What should I learn before this topic?
How can I practice it?
Is OAuth 2.0 hard to learn?
How long does it take to learn OAuth 2.0?
Which topics are related to OAuth 2.0?
What should I study after OAuth 2.0?
Related topics
- JWT (Web Development)
- CORS (Web Development)
- Authentication Flows (Web Development)
- Web Security Basics (Web Development)