Skip to content

Commit

Permalink
navikt#691 OAuth2TokenProvider should allow dynamic systemTime
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanswe committed May 29, 2024
1 parent 6de5473 commit 731f382
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 731f382

Please sign in to comment.