From 731f3827d46919a3524337bab929d2bb7daa401d Mon Sep 17 00:00:00 2001 From: xuanswe <24372782+xuanswe@users.noreply.github.com> Date: Wed, 29 May 2024 15:38:26 +0200 Subject: [PATCH] #691 `OAuth2TokenProvider` should allow dynamic `systemTime` --- .../mock/oauth2/token/OAuth2TokenProvider.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt b/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt index a8f12dafb..f6c0f2977 100644 --- a/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt +++ b/src/main/kotlin/no/nav/security/mock/oauth2/token/OAuth2TokenProvider.kt @@ -16,15 +16,25 @@ import no.nav.security.mock.oauth2.extensions.issuerId import okhttp3.HttpUrl import java.time.Duration import java.time.Instant -import java.util.Date -import java.util.UUID +import java.util.* + +typealias TimeProvider = () -> Instant? class OAuth2TokenProvider @JvmOverloads constructor( private val keyProvider: KeyProvider = KeyProvider(), - val systemTime: Instant? = null, + private val timeProvider: TimeProvider, ) { + val systemTime + get() = timeProvider() + + @JvmOverloads + constructor( + keyProvider: KeyProvider = KeyProvider(), + systemTime: Instant? = null, + ) : this(keyProvider, { systemTime }) + @JvmOverloads fun publicJwkSet(issuerId: String = "default"): JWKSet { return JWKSet(keyProvider.signingKey(issuerId)).toPublicJWKSet()