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()