How does OAuth2 login work in Spring Boot (Spring Security OAuth2 Client)? स्प्रिंग बूट में OAuth2 लॉगिन कैसे काम करता है (Spring Security OAuth2 Client)?
Spring Security's OAuth2 Client support lets an application delegate authentication to an external identity provider (Google, GitHub, Okta) using the OAuth2 Authorization Code flow. Adding spring-boot-starter-oauth2-client and configuring the provider's client ID, secret, and endpoints auto-configures the redirect, token exchange, and user-info retrieval.
After a successful login, Spring Security populates an OAuth2AuthenticationToken containing the user's attributes from the provider, and applications can map these attributes to internal roles through a custom OAuth2UserService. This is distinct from acting as an OAuth2 Resource Server, which instead validates incoming bearer tokens issued by an authorization server.
spring.security.oauth2.client.registration.google.client-id=YOUR_CLIENT_ID
spring.security.oauth2.client.registration.google.client-secret=YOUR_SECRET
spring.security.oauth2.client.registration.google.scope=email,profileस्प्रिंग सिक्योरिटी का OAuth2 Client सपोर्ट एप्लिकेशन को ऑथेंटिकेशन को Google, GitHub जैसे बाहरी आइडेंटिटी प्रोवाइडर को OAuth2 Authorization Code फ्लो के ज़रिए सौंपने देता है। spring-boot-starter-oauth2-client जोड़ना और प्रोवाइडर की client ID, secret कॉन्फिगर करना रीडायरेक्ट, टोकन एक्सचेंज और यूज़र-इंफो रिट्रीवल को ऑटो-कॉन्फिगर कर देता है।
सफल लॉगिन के बाद, स्प्रिंग सिक्योरिटी प्रोवाइडर से यूज़र की एट्रिब्यूट्स वाला OAuth2AuthenticationToken भरता है, और एप्लिकेशन कस्टम OAuth2UserService के ज़रिए इन एट्रिब्यूट्स को आंतरिक रोल्स से मैप कर सकते हैं।
spring.security.oauth2.client.registration.google.client-id=YOUR_CLIENT_ID
spring.security.oauth2.client.registration.google.client-secret=YOUR_SECRET
spring.security.oauth2.client.registration.google.scope=email,profileWas this answer clear?