Class DefaultTokenEndpointClient

java.lang.Object
io.micronaut.security.oauth2.endpoint.token.request.DefaultTokenEndpointClient
All Implemented Interfaces:
TokenEndpointClient

@Requires(beans=io.micronaut.http.client.HttpClientConfiguration.class) @Singleton public class DefaultTokenEndpointClient extends Object implements TokenEndpointClient
The default implementation of TokenEndpointClient.

The HTTP clients this class creates never follow redirects. The default client copies the settings of the HttpClientConfiguration. If an HttpClientConfiguration bean named after the provider exists (micronaut.http.services.<provider>.*), or an HttpClient bean named after the provider is declared, a client is created from that configuration (or from the default configuration when only the client bean exists) with the load balancer of the service. The named HttpClient bean itself is not used, because its redirect policy cannot be enforced.

Since:
1.2.0
Author:
James Kleeh
  • Constructor Details

    • DefaultTokenEndpointClient

      public DefaultTokenEndpointClient(@NonNull io.micronaut.context.BeanContext beanContext, io.micronaut.http.client.HttpClientConfiguration defaultClientConfiguration)
      Parameters:
      beanContext - The bean context
      defaultClientConfiguration - The default client configuration. Its settings are copied, but the client created from it never follows redirects.
    • DefaultTokenEndpointClient

      public DefaultTokenEndpointClient(@Nullable io.micronaut.context.BeanContext beanContext, Supplier<io.micronaut.http.client.HttpClient> defaultTokenClientSupplier)
      Parameters:
      beanContext - Bean Context
      defaultTokenClientSupplier - Default Token Client Supplier. The caller is responsible for configuring the client so that it does not follow redirects.
    • DefaultTokenEndpointClient

      public DefaultTokenEndpointClient(io.micronaut.http.client.HttpClient client)
      Parameters:
      client - HttpClient. The caller is responsible for configuring the client so that it does not follow redirects.
  • Method Details

    • sendRequest

      public <G, R extends TokenResponse> @NonNull org.reactivestreams.Publisher<R> sendRequest(TokenRequestContext<G,R> requestContext)
      Specified by:
      sendRequest in interface TokenEndpointClient
      Type Parameters:
      G - The token request grant or body
      R - The token response type
      Parameters:
      requestContext - The token request context
      Returns:
      a HTTP Request to the Token Endpoint with Authorization Code Grant payload.
    • secureRequest

      protected <G, R extends TokenResponse> void secureRequest(@NonNull io.micronaut.http.MutableHttpRequest<G> request, TokenRequestContext<G,R> requestContext)
      Secures the request according to the context's endpoint supported authentication methods.
      Type Parameters:
      G - The token request grant or body
      R - The token response type
      Parameters:
      request - Token endpoint Request
      requestContext - The request context
    • getClient

      protected io.micronaut.http.client.HttpClient getClient(String providerName)
      Retrieves a client for the given provider. The returned client never follows redirects.

      If an HttpClientConfiguration bean named after the provider exists, or an HttpClient bean named after the provider is declared, a client is created from the named configuration (or from the default configuration when only the client bean exists) with the load balancer of the service. Otherwise, the default client is returned.

      Parameters:
      providerName - The provider name
      Returns:
      An HTTP client to use to send the request
    • close

      @PreDestroy public void close()
      Closes the HTTP clients this bean created. A client supplied by the caller is not closed.
      Since:
      5.5.2