Skip to content

Commit aee55a6

Browse files
Fixed oauth2 for Android client, build authentication-service
1 parent 6687dcd commit aee55a6

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
package 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;
37
import org.springframework.stereotype.Controller;
8+
import org.springframework.ui.Model;
49
import org.springframework.web.bind.annotation.GetMapping;
510

11+
@Slf4j
612
@Controller
713
public 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
}

authentication-service/src/main/resources/application.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)