diff --git a/src/main/java/com/faforever/api/forum/NodebbService.java b/src/main/java/com/faforever/api/forum/NodebbService.java index 5b6f20d0b..24d1f9839 100644 --- a/src/main/java/com/faforever/api/forum/NodebbService.java +++ b/src/main/java/com/faforever/api/forum/NodebbService.java @@ -55,12 +55,13 @@ public void userDataChanged(UserUpdatedEvent event) { private Optional getNodebbUserId(int userId) { URI uri = UriComponentsBuilder.fromHttpUrl(properties.getNodebb().getBaseUrl()) // This is not an official NodeBB api url, it's coming from our own sso plugin - .pathSegment("api", "user", "oauth", String.valueOf(userId)) + .pathSegment("api", "v3", "plugins", "sso", "user", String.valueOf(userId)) + .queryParam("_uid", getAdminUserId()) .build() .toUri(); try { - ResponseEntity result = restTemplate.exchange(uri, HttpMethod.GET, null, UserResponse.class); + ResponseEntity result = restTemplate.exchange(uri, HttpMethod.GET, buildAuthorizedRequest(null), UserResponse.class); return Optional.ofNullable(result.getBody()).map(UserResponse::uid); } catch (HttpClientErrorException e) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -78,7 +79,7 @@ private void updateUsernameData(int nodebbUserId, UserUpdatedEvent event) { .build() .toUri(); - var usernameUpdate = new UsernameUpdate(String.valueOf(properties.getNodebb().getAdminUserId()), event.getUsername()); + var usernameUpdate = new UsernameUpdate(getAdminUserId(), event.getUsername()); restTemplate.exchange(uri, HttpMethod.PUT, buildAuthorizedRequest(usernameUpdate), Void.class); log.debug("Username updated in NodeBB: {}", event); } @@ -89,11 +90,15 @@ private void updateEmailData(int nodebbUserId, UserUpdatedEvent event) { .build() .toUri(); - var usernameUpdate = new EmailUpdate(String.valueOf(properties.getNodebb().getAdminUserId()), event.getEmail(), 1); - restTemplate.exchange(uri, HttpMethod.PUT, buildAuthorizedRequest(usernameUpdate), Void.class); + var usernameUpdate = new EmailUpdate(getAdminUserId(), event.getEmail(), 1); + restTemplate.exchange(uri, HttpMethod.POST, buildAuthorizedRequest(usernameUpdate), Void.class); log.debug("Email updated in NodeBB: {}", event); } + private String getAdminUserId() { + return String.valueOf(properties.getNodebb().getAdminUserId()); + } + private HttpEntity buildAuthorizedRequest(T payload) { LinkedMultiValueMap headers = new LinkedMultiValueMap<>(); headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + properties.getNodebb().getMasterToken());