Class TokenHandler

  • All Implemented Interfaces:
    LightHttpHandler, MiddlewareHandler, io.undertow.server.HttpHandler

    public class TokenHandler
    extends Object
    implements MiddlewareHandler
    This is a middleware handler that is responsible for getting a JWT access token from OAuth 2.0 provider for the particular router client. The only token that is supported in this handler is client credentials token as there is no user information available here. The client_id and client_secret will be retrieved from client.yml and client_secret should be encrypted or set as an environment variable. In Kubernetes cluster, you can create a sealed secret for it. This handler will also responsible for checking if the cached token is about expired or not. In which case, it will renew the token in another thread. When request comes and the cached token is already expired, then it will block the request and go to the OAuth provider to get a new token and then resume the request to the next handler in the chain. The logic is very similar with client module in light-4j but this is implemented in a handler instead. Multiple OAuth 2.0 providers are supported and the token cache strategy can be defined based on your OAuth 2.0 providers. This light-router is designed for standalone or client that is not implemented in Java Otherwise, you should use client module instead of this one. In the future, we might add Authorization Code grant type support by providing an endpoint in the light-router to accept Authorization Code redirect and then get the token from OAuth 2.0 provider. There is no specific configuration file for this handler just to enable or disable it. If you want to bypass this handler, you can comment it out from handler.yml middleware handler section or change the token.yml to disable it. Once the token is retrieved from OAuth 2.0 provider, it will be placed in the header as Authorization Bearer token according to the OAuth 2.0 specification.
    • Field Detail

      • next

        protected volatile io.undertow.server.HttpHandler next
    • Constructor Detail

      • TokenHandler

        public TokenHandler()