Skip to content

Commit

Permalink
Use system token towards klage-file-api. Access is ensured by checkin…
Browse files Browse the repository at this point in the history
…g token and klanke in this app.
  • Loading branch information
oyvind-wedoe committed Oct 9, 2024
1 parent 0cb21eb commit d0a54a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/no/nav/klage/clients/FileClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FileClient(
val response = fileWebClient
.post()
.uri { it.path("/attachment").build() }
.header(HttpHeaders.AUTHORIZATION, "Bearer ${tokenUtil.getOnBehalfOfTokenWithKlageFileApiScope()}")
.header(HttpHeaders.AUTHORIZATION, "Bearer ${tokenUtil.getAppAccessTokenWithKlageFileApiScope()}")
.body(BodyInserters.fromMultipartData(bodyBuilder.build()))
.retrieve()
.bodyToMono<VedleggResponse>()
Expand All @@ -47,7 +47,7 @@ class FileClient(
logger.debug("Fetching vedlegg file with vedlegg ref {}", vedleggRef)
return fileWebClient.get()
.uri { it.path("/attachment/{id}").build(vedleggRef) }
.header(HttpHeaders.AUTHORIZATION, "Bearer ${tokenUtil.getOnBehalfOfTokenWithKlageFileApiScope()}")
.header(HttpHeaders.AUTHORIZATION, "Bearer ${tokenUtil.getAppAccessTokenWithKlageFileApiScope()}")
.retrieve()
.bodyToMono<ByteArray>()
.block() ?: throw RuntimeException("Attachment could not be fetched")
Expand All @@ -57,7 +57,7 @@ class FileClient(
logger.debug("Deleting vedlegg file with vedlegg ref {}", vedleggRef)
val deletedInFileStore = fileWebClient.delete()
.uri { it.path("/attachment/{id}").build(vedleggRef) }
.header(HttpHeaders.AUTHORIZATION, "Bearer ${tokenUtil.getOnBehalfOfTokenWithKlageFileApiScope()}")
.header(HttpHeaders.AUTHORIZATION, "Bearer ${tokenUtil.getAppAccessTokenWithKlageFileApiScope()}")
.retrieve()
.bodyToMono<Boolean>()
.block()!!
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/no/nav/klage/util/TokenUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ class TokenUtil(
return response.accessToken!!
}

fun getOnBehalfOfTokenWithKlageFileApiScope(): String {
val clientProperties = clientConfigurationProperties.registration["klage-file-api-onbehalfof"]!!
secureLogger.debug("Getting clientProperties for klage-file-api-onbehalfof: {}", clientProperties)
fun getAppAccessTokenWithKlageFileApiScope(): String {
val clientProperties = clientConfigurationProperties.registration["klage-file-api-maskintilmaskin"]!!
val response = oAuth2AccessTokenService.getAccessToken(clientProperties)
return response.accessToken!!
}
Expand Down
16 changes: 6 additions & 10 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ no.nav.security.jwt:
client-auth-method: private_key_jwt
token-exchange:
audience: ${SAFSELVBETJENING_AUDIENCE}
klage-file-api-onbehalfof:
token-endpoint-url: ${TOKEN_X_TOKEN_ENDPOINT}
grant_type: urn:ietf:params:oauth:grant-type:token-exchange
client_assertion_type: urn:ietf:params:oauth:client-assertion-type:jwt-bearer
subject_token_type: urn:ietf:params:oauth:token-type:jwt
audience: ${KLAGE_FILE_API_AUDIENCE}
klage-file-api-maskintilmaskin:
token-endpoint-url: https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token
grant-type: client_credentials
scope: api://${NAIS_CLUSTER_NAME}.${NAIS_NAMESPACE}.${KLAGE_FILE_API_APP_NAME}/.default
authentication:
client-id: ${TOKEN_X_CLIENT_ID}
client-jwk: ${TOKEN_X_PRIVATE_JWK}
client-id: ${AZURE_APP_CLIENT_ID}
client-jwk: ${AZURE_APP_JWK}
client-auth-method: private_key_jwt
token-exchange:
audience: ${KLAGE_FILE_API_AUDIENCE}
klage-fss-proxy-maskintilmaskin:
token-endpoint-url: https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token
grant-type: client_credentials
Expand Down

0 comments on commit d0a54a2

Please sign in to comment.