Skip to content

Commit

Permalink
Use machine token for dokarkiv
Browse files Browse the repository at this point in the history
  • Loading branch information
dragutin-nav committed Apr 23, 2024
1 parent df61444 commit e62a699
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import no.nav.common.health.HealthCheckResult
import no.nav.common.health.HealthCheckUtils
import no.nav.common.rest.client.RestClient
import no.nav.common.rest.client.RestUtils
import no.nav.common.utils.AuthUtils
import no.nav.common.utils.UrlUtils.joinPaths
import no.nav.veilarbvedtaksstotte.client.dokarkiv.request.OpprettJournalpostDTO
import no.nav.veilarbvedtaksstotte.client.dokarkiv.request.OpprettetJournalpostDTO
Expand All @@ -23,7 +24,7 @@ import java.util.function.Supplier
@Slf4j
class DokarkivClientImpl(
val dokarkivUrl: String,
val userTokenSupplier: Supplier<String>
val machineToMachineTokenClient: Supplier<String>
) : DokarkivClient {

val log: Logger = LoggerFactory.getLogger(DokarkivClientImpl::class.java)
Expand All @@ -33,7 +34,7 @@ class DokarkivClientImpl(
override fun opprettJournalpost(opprettJournalpostDTO: OpprettJournalpostDTO): OpprettetJournalpostDTO {
val request = Request.Builder()
.url(joinPaths(dokarkivUrl, "/rest/journalpostapi/v1/journalpost?forsoekFerdigstill=true"))
.header(HttpHeaders.AUTHORIZATION, userTokenSupplier.get())
.header(HttpHeaders.AUTHORIZATION, AuthUtils.bearerToken(machineToMachineTokenClient.get()))
.post(opprettJournalpostDTO.toJson().toRequestBody(RestUtils.MEDIA_TYPE_JSON))
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,16 @@ class ClientConfig {
}

@Bean
fun dokarkivClient(oboContexService: OboContexService): DokarkivClient {
fun dokarkivClient(tokenClient: AzureAdMachineToMachineTokenClient): DokarkivClient {
val dokarkivClient = dokarkiv.invoke(if (isProduction) "prod-fss" else "dev-fss")
val userTokenSupplier = oboContexService.userTokenSupplier(dokarkivClient)

val url =
if (isProduction) UrlUtils.createProdInternalIngressUrl(dokarkivClient.serviceName) else UrlUtils.createDevInternalIngressUrl(
dokarkivClient.serviceName
)
return DokarkivClientImpl(
url,
userTokenSupplier
)
url
){ tokenClient.createMachineToMachineToken(tokenScope(dokarkivClient)) }
}

@Bean
Expand Down

0 comments on commit e62a699

Please sign in to comment.