diff --git a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedToken.java b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedToken.java index 0a5d4e957fd..c69106248ed 100644 --- a/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedToken.java +++ b/libs/reactive-security/src/main/java/no/nav/testnav/libs/reactivesecurity/action/GetAuthenticatedToken.java @@ -28,19 +28,13 @@ public Mono call() { .call() .flatMap(serverType -> switch (serverType) { case TOKEN_X -> getJwtAuthenticationToken() - .map(OAuth2AuthenticationToken.class::cast) - .handle((oauth2, sink) -> { - try { - sink.next(Token.builder() - .clientCredentials(false) - .userId(oauth2.getPrincipal().getAttributes().get("pid").toString()) - .accessTokenValue(new ObjectMapper().writeValueAsString(oauth2)) - .expiresAt((Instant) oauth2.getPrincipal().getAttributes().get("exp")) - .build()); - } catch (JsonProcessingException e) { - sink.error(new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Feilet å konvertere token to string", e)); - } - }); + .map(JwtAuthenticationToken.class::cast) + .map(jwt -> Token.builder() + .clientCredentials(false) + .userId(jwt.getTokenAttributes().get("pid").toString()) + .accessTokenValue(jwt.getToken().getTokenValue()) + .expiresAt(jwt.getToken().getExpiresAt()) + .build()); case AZURE_AD -> getJwtAuthenticationToken() .map(JwtAuthenticationToken.class::cast) .map(jwt -> Token.builder()