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 402e568
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,23 @@ import java.time.Instant
import java.util.Date
import java.util.UUID

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 402e568

Please sign in to comment.