Skip to content

Traefik Middleware to check incoming request's Authorization token to see if that's valid or not using an API call. Avoiding duplicating verification code.

License

Notifications You must be signed in to change notification settings

sorasful/traefik-jwt-optional-api-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT Middleware API Validator

JWT Middleware API Validator is a middleware plugin for Traefik which verifies a jwt token and adds the payload as injected header to the request

Meaning that if the authorization code is in the request, it will get checked, and if it does, the request will go through. The way the request is checked is by sending a GET request to a specific endpoint that you can override with ValidateAPIUrl. If it returns a 200 response, it will go through.

If you want to check that a request is authenticated you'll need to verify that there is a Authorization header in your request. You can also check the header that is injected ProxyHeaderName which is injectedPayload by default.

We delete it from the incoming requests, just in case.

This plugin is heavily inspired by : https://github.com/23deg/jwt-middleware

Configuration

Start with command

command:
  - "--experimental.plugins.traefik-jwt-optional-api-validator.modulename=github.com/sorasful/traefik-jwt-optional-api-validator"
  - "--experimental.plugins.traefik-jwt-optional-api-validator.version=v0.0.14"

Activate plugin in your config

http:
  middlewares:
    my-jwt-middleware:
      plugin:
        traefik-jwt-optional-api-validator:
          proxyHeaderName: injectedPayload
          authHeader: Authorization
          headerPrefix: Bearer
          optional: true
          ValidateAPIUrl: http://yourAPI/validate-token

Use as docker-compose label

  labels:
        - "traefik.http.routers.my-service.middlewares=my-jwt-middleware@file"

About

Traefik Middleware to check incoming request's Authorization token to see if that's valid or not using an API call. Avoiding duplicating verification code.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages