Skip to content

Commit 0fa062b

Browse files
committed
fix subject Id not populated
1 parent c691010 commit 0fa062b

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
- "8080:8080"
2020
environment:
2121
REACT_APP_API: http://localhost:8081
22-
REACT_APP_EGO_CLIENT_ID: ego-local
22+
REACT_APP_EGO_CLIENT_ID: ego-ui
2323
REACT_APP_KEYCLOAK_ENABLED: "true"
2424
postgres:
2525
image: postgres:12.6

src/main/java/bio/overture/ego/controller/AuthController.java

+1-16
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,8 @@ public ResponseEntity<String> user(
140140
if (Objects.isNull(authentication.getPrincipal())) {
141141
throw new RuntimeException("no user");
142142
}
143-
CustomOAuth2User user;
144-
if (authentication.getPrincipal() instanceof OidcUser) {
145-
val p = (OidcUser) authentication.getPrincipal();
146-
user =
147-
CustomOAuth2User.builder()
148-
.subjectId(p.getUserInfo().getSubject())
149-
.givenName(p.getUserInfo().getGivenName())
150-
.familyName(p.getUserInfo().getFamilyName())
151-
.email(p.getUserInfo().getEmail())
152-
.oauth2User(p)
153-
.build();
154-
} else if (authentication.getPrincipal() instanceof CustomOAuth2User) {
155-
user = (CustomOAuth2User) authentication.getPrincipal();
156-
} else {
157-
throw new RuntimeException();
158-
}
159143

144+
val user = (CustomOAuth2User) authentication.getPrincipal();
160145
String token =
161146
tokenService.generateUserToken(
162147
IDToken.builder()

src/main/java/bio/overture/ego/security/CustomOAuth2UserInfoService.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ public CustomOAuth2User loadUser(OAuth2UserRequest oAuth2UserRequest)
5353
.familyName(info.getOrDefault(FAMILY_NAME, "").toString())
5454
.givenName(info.getOrDefault(GIVEN_NAME, "").toString())
5555
.build();
56-
}
57-
58-
if (provider.equalsIgnoreCase(ProviderType.LINKEDIN.toString())) {
56+
} else if (provider.equalsIgnoreCase(ProviderType.LINKEDIN.toString())) {
5957
val info = getLinkedInUserInfo(oAuth2User, oAuth2UserRequest);
6058
return CustomOAuth2User.builder()
6159
.oauth2User(new DefaultOAuth2User(oAuth2User.getAuthorities(), info, idName))
@@ -64,9 +62,10 @@ public CustomOAuth2User loadUser(OAuth2UserRequest oAuth2UserRequest)
6462
.familyName(info.getOrDefault(FAMILY_NAME, "").toString())
6563
.givenName(info.getOrDefault(GIVEN_NAME, "").toString())
6664
.build();
65+
} else {
66+
throw new RuntimeException("unhandled provider type " + provider);
6767
}
6868

69-
return CustomOAuth2User.builder().oauth2User(oAuth2User).build();
7069
} catch (AuthenticationException ex) {
7170
throw ex;
7271
} catch (Exception ex) {

src/main/java/bio/overture/ego/security/CustomOidc2UserInfoService.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ public OidcUser loadUser(OidcUserRequest oAuth2UserRequest) throws OAuth2Authent
4848
.givenName(info.getOrDefault(GIVEN_NAME, "").toString())
4949
.build();
5050
}
51-
return CustomOAuth2User.builder().oauth2User(oidcUser).build();
51+
return CustomOAuth2User.builder()
52+
.oauth2User(oidcUser)
53+
.subjectId(oidcUser.getSubject())
54+
.email(oidcUser.getEmail())
55+
.familyName(oidcUser.getFamilyName())
56+
.givenName(oidcUser.getGivenName())
57+
.build();
5258
} catch (AuthenticationException ex) {
5359
throw ex;
5460
} catch (Exception ex) {

0 commit comments

Comments
 (0)