refactor(deposit, user): rename Keycloak to Authentik user info
Some checks failed
CI / Get Changed Files (pull_request) Successful in 6s
CI / eslint (pull_request) Failing after 25s
CI / test-build (pull_request) Successful in 33s
CI / prettier (pull_request) Failing after 56s
CI / Checkstyle Main (pull_request) Successful in 2m0s

This commit is contained in:
Jan K9f 2025-04-02 16:09:34 +02:00
parent d7fe0e3965
commit fa09a8533f
Signed by: jank
GPG key ID: B9F475106B20F144
4 changed files with 23 additions and 5 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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;
}

View file

@ -12,12 +12,28 @@ spring.application.name=lf12_starter
spring.security.oauth2.client.registration.authentik.client-id=MDqjm1kcWKuZfqHJXjxwAV20i44aT7m4VhhTL3Nm
spring.security.oauth2.client.registration.authentik.client-secret=GY2F8te6iAVYt1TNAUVLzWZEXb6JoMNp6chbjqaXNq4gS5xTDL54HqBiAlV1jFKarN28LQ7FUsYX4SbwjfEhZhgeoKuBnZKjR9eiu7RawnGgxIK9ffvUfMkjRxnmiGI5
spring.security.oauth2.client.registration.authentik.provider=authentik
spring.security.oauth2.client.registration.authentik.client-name=Authentik
spring.security.oauth2.client.registration.authentik.scope=openid,email,profile
spring.security.oauth2.client.registration.authentik.client-authentication-method=client_secret_basic
spring.security.oauth2.client.registration.authentik.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.authentik.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}
# Provider settings
spring.security.oauth2.client.provider.authentik.issuer-uri=https://oauth.simonis.lol/application/o/casino-dev/
spring.security.oauth2.client.provider.authentik.authorization-uri=https://oauth.simonis.lol/application/o/authorize/
spring.security.oauth2.client.provider.authentik.token-uri=https://oauth.simonis.lol/application/o/token/
spring.security.oauth2.client.provider.authentik.user-info-uri=https://oauth.simonis.lol/application/o/userinfo/
spring.security.oauth2.client.provider.authentik.jwk-set-uri=https://oauth.simonis.lol/application/o/casino-dev/jwks/
spring.security.oauth2.client.provider.authentik.user-name-attribute=preferred_username
# Resource server config
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://oauth.simonis.lol/application/o/casino-dev/
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://oauth.simonis.lol/application/o/casino-dev/jwks/
#OIDC provider configuration:
logging.level.org.springframework.security=DEBUG
#validating JWT token against our Keycloak server
#validating JWT token against our Authentik server
springdoc.swagger-ui.path=swagger
springdoc.swagger-ui.try-it-out-enabled=true