refactor(deposit, user): rename Keycloak to Authentik user info
Some checks failed
Some checks failed
This commit is contained in:
parent
d7fe0e3965
commit
fa09a8533f
4 changed files with 23 additions and 5 deletions
|
@ -47,7 +47,7 @@ public class DepositController {
|
|||
public ResponseEntity<SessionIdDto> checkout(@RequestBody @Valid AmountDto amountDto, @RequestHeader("Authorization") String token) throws StripeException {
|
||||
Stripe.apiKey = stripeKey;
|
||||
|
||||
KeycloakUserDto userData = getKeycloakUserInfo(token);
|
||||
KeycloakUserDto userData = getAuthentikUserInfo(token);
|
||||
Optional<UserEntity> optionalUserEntity = this.userRepository.findOneByAuthentikId(userData.getSub());
|
||||
|
||||
SessionCreateParams params = SessionCreateParams.builder()
|
||||
|
@ -77,7 +77,7 @@ public class DepositController {
|
|||
return ResponseEntity.ok(new SessionIdDto(session.getId()));
|
||||
}
|
||||
|
||||
private KeycloakUserDto getKeycloakUserInfo(String token) {
|
||||
private KeycloakUserDto getAuthentikUserInfo(String token) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Authorization", token);
|
||||
ResponseEntity<KeycloakUserDto> response = this.restTemplate.exchange("https://oauth.simonis.lol/application/o/userinfo/", HttpMethod.GET, new HttpEntity<>(headers), KeycloakUserDto.class);
|
||||
|
|
|
@ -49,12 +49,12 @@ public class UserService {
|
|||
}
|
||||
|
||||
public Optional<UserEntity> getCurrentUser(String token) {
|
||||
KeycloakUserDto userData = getKeycloakUserInfo(token);
|
||||
KeycloakUserDto userData = getAuthentikUserInfo(token);
|
||||
|
||||
if (userData == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return this.userRepository.findOneByKeycloakId(userData.getSub());
|
||||
return this.userRepository.findOneByAuthentikId(userData.getSub());
|
||||
}
|
||||
|
||||
private KeycloakUserDto getAuthentikUserInfo(String token) {
|
||||
|
|
|
@ -10,6 +10,8 @@ import lombok.Setter;
|
|||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class KeycloakUserDto {
|
||||
// Renamed class but kept for backward compatibility
|
||||
// This now contains Authentik user info
|
||||
private String sub;
|
||||
private String preferred_username;
|
||||
}
|
||||
|
|
Reference in a new issue