MockOAuth2Server

open class MockOAuth2Server(val config: OAuth2Config = OAuth2Config(), additionalRoutes: Route)

Constructors

Link copied to clipboard
constructor(vararg additionalRoutes: Route)
constructor(config: OAuth2Config)
constructor(config: OAuth2Config = OAuth2Config(), vararg additionalRoutes: Route)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun anyToken(issuerUrl: HttpUrl, claims: Map<String, Any>, expiry: Duration = Duration.ofHours(1)): SignedJWT

Issues a signed JWT for a given issuerUrl containing the input set of claims. The JWT's signature can be verified with the server's keys found at the jwksUrl endpoint.

Link copied to clipboard
fun authorizationEndpointUrl(issuerId: String): HttpUrl

Returns the authorization server's authorization_endpoint for the given issuerId.

Link copied to clipboard
fun baseUrl(): HttpUrl

Returns the base URL for this server.

Link copied to clipboard
fun endSessionEndpointUrl(issuerId: String): HttpUrl

Returns the authorization server's end_session_endpoint for the given issuerId.

Link copied to clipboard
fun enqueueCallback(oAuth2TokenCallback: OAuth2TokenCallback): Boolean

Enqueues a callback at the server's HTTP request handler. This allows for customization of the token that the server issues whenever a Relying Party requests a token from the tokenEndpointUrl.

Link copied to clipboard
fun enqueueResponse(response: MockResponse)
Link copied to clipboard
fun issuerUrl(issuerId: String): HttpUrl

Returns the authorization server's issuer for the given issuerId.

Link copied to clipboard
fun issueToken(issuerId: String, clientId: String, tokenCallback: OAuth2TokenCallback): SignedJWT

Issues a signed JWT as part of the authorization code grant.

fun issueToken(    issuerId: String = "default",     subject: String = UUID.randomUUID().toString(),     audience: String? = "default",     claims: Map<String, Any> = emptyMap(),     expiry: Long = 3600): SignedJWT

Convenience method for issuing a signed JWT with default values.

Link copied to clipboard
fun jwksUrl(issuerId: String): HttpUrl

Returns the authorization server's jwks_uri for the given issuerId.

Link copied to clipboard

Returns the authorization server's well-known OAuth2 metadata discovery URL for the given issuerId.

Link copied to clipboard
fun revocationEndpointUrl(issuerId: String): HttpUrl

Returns the authorization server's revocation_endpoint for the given issuerId.

Link copied to clipboard
fun shutdown()

Gracefully shuts down the MockOAuth2Server.

Link copied to clipboard
fun start(port: Int = 0)

Starts the MockOAuth2Server on the localhost interface.

fun start(inetAddress: InetAddress, port: Int)

Starts the MockOAuth2Server on the given inetAddress IP address at the given port.

Link copied to clipboard
fun takeRequest(timeout: Long = 2, unit: TimeUnit = TimeUnit.SECONDS): RecordedRequest

Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it from the queue, and returns it. Callers should use this to verify the request was sent as intended within the given time.

Link copied to clipboard
fun tokenEndpointUrl(issuerId: String): HttpUrl

Returns the authorization server's token_endpoint for the given issuerId.

Link copied to clipboard
fun url(path: String): HttpUrl

Returns the authorization server's issuer identifier for the given path. The identifier is a URL without query or fragment components, e.g. http://localhost:8080/some-issuer.

Link copied to clipboard
fun userInfoUrl(issuerId: String): HttpUrl

Returns the authorization server's userinfo_endpoint for the given issuerId.

Link copied to clipboard
fun wellKnownUrl(issuerId: String): HttpUrl

Returns the authorization server's well-known OpenID Connect metadata discovery URL for the given issuerId.