How does OAuth2 authentication work?

OAuth2 is an authorization protocol that lets a user grant a third-party application limited access to their data on another service, without ever sharing their password with that application.

Key Points

Example

Clicking "Sign in with Google" on a third-party site sends you to Google's login page; after you approve, Google gives the site a token that lets it read your profile but never exposes your Google password to that site.

Interview Tip

A concise interview answer is

OAuth2 lets a user authorize an application to access their data without sharing credentials. The flow redirects the user to the provider's login, the provider issues an authorization code after consent, and the app exchanges that code for an access token it uses on future API calls.

Last updated: 11 November 2026

Previous question: What is SLF4J logging?

Next question: What details are present in a JWT token?

More Spring Security - Level II interview questions

All Spring Security - Level II questions