Class MockOAuth2Server
-
- All Implemented Interfaces:
public class MockOAuth2Server
-
-
Field Summary
Fields Modifier and Type Field Description private final OAuth2Configconfig
-
Constructor Summary
Constructors Constructor Description MockOAuth2Server(Route additionalRoutes)MockOAuth2Server(OAuth2Config config)MockOAuth2Server(OAuth2Config config, Route additionalRoutes)
-
Method Summary
Modifier and Type Method Description final OAuth2ConfiggetConfig()final Unitstart(Integer port)Starts the MockOAuth2Server on the localhost interface. final Unitstart()Starts the MockOAuth2Server on the localhost interface. final Unitstart(InetAddress inetAddress, Integer port)Starts the MockOAuth2Server on the given inetAddress IP address at the given port. final Unitshutdown()Gracefully shuts down the MockOAuth2Server. final HttpUrlurl(String path)Returns the authorization server's issuer identifier for the given path. final UnitenqueueResponse(MockResponse response)final BooleanenqueueCallback(OAuth2TokenCallback oAuth2TokenCallback)Enqueues a callback at the server's HTTP request handler. final RecordedRequesttakeRequest(Long timeout, TimeUnit unit)Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it from the queue, and returns it. final RecordedRequesttakeRequest(Long timeout)Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it from the queue, and returns it. final RecordedRequesttakeRequest()Awaits the next HTTP request (waiting up to the specified wait time if necessary), removes it from the queue, and returns it. final HttpUrlwellKnownUrl(String issuerId)Returns the authorization server's well-known OpenID Connect metadata discovery URL for the given issuerId. final HttpUrloauth2AuthorizationServerMetadataUrl(String issuerId)Returns the authorization server's well-known OAuth2 metadata discovery URL for the given issuerId. final HttpUrltokenEndpointUrl(String issuerId)Returns the authorization server's token_endpointfor the given issuerId.final HttpUrljwksUrl(String issuerId)Returns the authorization server's jwks_urifor the given issuerId.final HttpUrlissuerUrl(String issuerId)Returns the authorization server's issuerfor the given issuerId.final HttpUrlauthorizationEndpointUrl(String issuerId)Returns the authorization server's authorization_endpointfor the given issuerId.final HttpUrlendSessionEndpointUrl(String issuerId)Returns the authorization server's end_session_endpointfor the given issuerId.final HttpUrlrevocationEndpointUrl(String issuerId)Returns the authorization server's revocation_endpointfor the given issuerId.final HttpUrluserInfoUrl(String issuerId)Returns the authorization server's userinfo_endpointfor the given issuerId.final HttpUrlbaseUrl()Returns the base URL for this server. final SignedJWTissueToken(String issuerId, String clientId, OAuth2TokenCallback tokenCallback)Issues a signed JWT as part of the authorization code grant. final SignedJWTissueToken(String issuerId, String subject, String audience, Map<String, Object> claims, Long expiry)Convenience method for issuing a signed JWT with default values. final SignedJWTissueToken(String issuerId, String subject, String audience, Map<String, Object> claims)Convenience method for issuing a signed JWT with default values. final SignedJWTissueToken(String issuerId, String subject, String audience)Convenience method for issuing a signed JWT with default values. final SignedJWTissueToken(String issuerId, String subject)Convenience method for issuing a signed JWT with default values. final SignedJWTissueToken(String issuerId)Convenience method for issuing a signed JWT with default values. final SignedJWTissueToken()Convenience method for issuing a signed JWT with default values. final SignedJWTanyToken(HttpUrl issuerUrl, Map<String, Object> claims, Duration expiry)Issues a signed JWT for a given issuerUrl containing the input set of claims. final SignedJWTanyToken(HttpUrl issuerUrl, Map<String, Object> claims)Issues a signed JWT for a given issuerUrl containing the input set of claims. -
-
Constructor Detail
-
MockOAuth2Server
MockOAuth2Server(Route additionalRoutes)
-
MockOAuth2Server
MockOAuth2Server(OAuth2Config config)
-
MockOAuth2Server
MockOAuth2Server(OAuth2Config config, Route additionalRoutes)
-
-
Method Detail
-
getConfig
final OAuth2Config getConfig()
-
start
@JvmOverloads() final Unit start(Integer port)
Starts the MockOAuth2Server on the localhost interface.
- Parameters:
port- The port the server should listen on, a value of 0 (which is the default) selects any available port.
-
start
@JvmOverloads() final Unit start()
Starts the MockOAuth2Server on the localhost interface.
-
start
final Unit start(InetAddress inetAddress, Integer port)
Starts the MockOAuth2Server on the given inetAddress IP address at the given port.
- Parameters:
inetAddress- The IP address that the server should bind to.port- The port that the server should listen on, a value of 0 selects any available port.
-
shutdown
final Unit shutdown()
Gracefully shuts down the MockOAuth2Server.
-
url
final HttpUrl url(String path)
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.- Parameters:
path- The path or identifier for the issuer.
-
enqueueResponse
@Deprecated(message = "Use MockWebServer method/function instead", replaceWith = @ReplaceWith(imports = {}, expression = "MockWebServer.enqueue()")) final Unit enqueueResponse(MockResponse response)
-
enqueueCallback
final Boolean enqueueCallback(OAuth2TokenCallback oAuth2TokenCallback)
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.
- Parameters:
oAuth2TokenCallback- A callback that implements the OAuth2TokenCallback interface.
-
takeRequest
@JvmOverloads() final RecordedRequest takeRequest(Long timeout, TimeUnit unit)
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.
-
takeRequest
@JvmOverloads() final RecordedRequest takeRequest(Long timeout)
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.
- Parameters:
timeout- How long to wait before giving up, in units of unit
-
takeRequest
@JvmOverloads() final RecordedRequest takeRequest()
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.
-
wellKnownUrl
final HttpUrl wellKnownUrl(String issuerId)
Returns the authorization server's well-known OpenID Connect metadata discovery URL for the given issuerId.
E.g.
http://localhost:8080/some-issuer/.well-known/openid-configuration.See also OpenID Provider metadata.
- Parameters:
issuerId- The path or identifier for the issuer.
-
oauth2AuthorizationServerMetadataUrl
final HttpUrl oauth2AuthorizationServerMetadataUrl(String issuerId)
Returns the authorization server's well-known OAuth2 metadata discovery URL for the given issuerId.
E.g.
http://localhost:8080/some-issuer/.well-known/oauth-authorization-server.- Parameters:
issuerId- The path or identifier for the issuer.
-
tokenEndpointUrl
final HttpUrl tokenEndpointUrl(String issuerId)
Returns the authorization server's
token_endpointfor the given issuerId.E.g.
http://localhost:8080/some-issuer/token.- Parameters:
issuerId- The path or identifier for the issuer.
-
jwksUrl
final HttpUrl jwksUrl(String issuerId)
Returns the authorization server's
jwks_urifor the given issuerId.E.g.
http://localhost:8080/some-issuer/jwks.- Parameters:
issuerId- The path or identifier for the issuer.
-
authorizationEndpointUrl
final HttpUrl authorizationEndpointUrl(String issuerId)
Returns the authorization server's
authorization_endpointfor the given issuerId.E.g.
http://localhost:8080/some-issuer/authorize.- Parameters:
issuerId- The path or identifier for the issuer.
-
endSessionEndpointUrl
final HttpUrl endSessionEndpointUrl(String issuerId)
Returns the authorization server's
end_session_endpointfor the given issuerId.E.g.
http://localhost:8080/some-issuer/endsession.- Parameters:
issuerId- The path or identifier for the issuer.
-
revocationEndpointUrl
final HttpUrl revocationEndpointUrl(String issuerId)
Returns the authorization server's
revocation_endpointfor the given issuerId.E.g.
http://localhost:8080/some-issuer/revoke.- Parameters:
issuerId- The path or identifier for the issuer.
-
userInfoUrl
final HttpUrl userInfoUrl(String issuerId)
Returns the authorization server's
userinfo_endpointfor the given issuerId.E.g.
http://localhost:8080/some-issuer/userinfo.- Parameters:
issuerId- The path or identifier for the issuer.
-
baseUrl
final HttpUrl baseUrl()
Returns the base URL for this server.
-
issueToken
final SignedJWT issueToken(String issuerId, String clientId, OAuth2TokenCallback tokenCallback)
Issues a signed JWT as part of the authorization code grant.
- Parameters:
issuerId- The path or identifier for the issuer.clientId- The identifier for the client or Relying Party that requests the token.tokenCallback- A callback that implements the OAuth2TokenCallback interface for token customization.
-
issueToken
@JvmOverloads() final SignedJWT issueToken(String issuerId, String subject, String audience, Map<String, Object> claims, Long expiry)
Convenience method for issuing a signed JWT with default values.
See issueToken.
-
issueToken
@JvmOverloads() final SignedJWT issueToken(String issuerId, String subject, String audience, Map<String, Object> claims)
Convenience method for issuing a signed JWT with default values.
See issueToken.
-
issueToken
@JvmOverloads() final SignedJWT issueToken(String issuerId, String subject, String audience)
Convenience method for issuing a signed JWT with default values.
See issueToken.
-
issueToken
@JvmOverloads() final SignedJWT issueToken(String issuerId, String subject)
Convenience method for issuing a signed JWT with default values.
See issueToken.
-
issueToken
@JvmOverloads() final SignedJWT issueToken(String issuerId)
Convenience method for issuing a signed JWT with default values.
See issueToken.
-
issueToken
@JvmOverloads() final SignedJWT issueToken()
Convenience method for issuing a signed JWT with default values.
See issueToken.
-
anyToken
@JvmOverloads() final SignedJWT anyToken(HttpUrl issuerUrl, Map<String, Object> claims, Duration expiry)
-
anyToken
@JvmOverloads() final SignedJWT anyToken(HttpUrl issuerUrl, Map<String, Object> claims)
-
-
-
-