File tree Expand file tree Collapse file tree
authentication-service/src/main
java/com/microservice/authentication/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .microservice .authentication .controller ;
22
3+ import jakarta .servlet .http .HttpServletRequest ;
4+ import lombok .extern .slf4j .Slf4j ;
5+ import org .springframework .security .core .Authentication ;
6+ import org .springframework .security .core .context .SecurityContextHolder ;
37import org .springframework .stereotype .Controller ;
8+ import org .springframework .ui .Model ;
49import org .springframework .web .bind .annotation .GetMapping ;
510
11+ @ Slf4j
612@ Controller
713public class AndroidOAuth2Controller {
814
915 @ GetMapping ("/android/oauth2/callback" )
10- public String androidOAuth2Callback () {
16+ public String androidOAuth2Callback (HttpServletRequest request , Model model ) {
1117 // After successful OAuth2 authentication with Google,
1218 // Spring Security redirects here with authenticated session
1319 // Android app will intercept this URL via intent-filter
1420 // and handle the authentication
21+
22+ Authentication auth = SecurityContextHolder .getContext ().getAuthentication ();
23+ if (auth != null && auth .isAuthenticated ()) {
24+ log .info ("Android OAuth2 callback - User authenticated: {}" , auth .getName ());
25+ model .addAttribute ("username" , auth .getName ());
26+ model .addAttribute ("sessionId" , request .getSession ().getId ());
27+ }
28+
1529 return "oauth2-android-success" ;
1630 }
1731}
Original file line number Diff line number Diff line change @@ -78,6 +78,11 @@ spring:
7878 google :
7979 client-id : ${CLIENT_ID}
8080 client-secret : ${CLIENT_SECRET}
81+ scope :
82+ - openid
83+ - profile
84+ - email
85+ redirect-uri : " {baseUrl}/login/oauth2/code/{registrationId}"
8186 authorizationserver :
8287 client :
8388 google :
@@ -138,6 +143,11 @@ spring:
138143 google :
139144 client-id : ${CLIENT_ID}
140145 client-secret : ${CLIENT_SECRET}
146+ scope :
147+ - openid
148+ - profile
149+ - email
150+ redirect-uri : " {baseUrl}/login/oauth2/code/{registrationId}"
141151 authorizationserver :
142152 client :
143153 google :
You can’t perform that action at this time.
0 commit comments