Simple http server that can receive a JWT in the http request and answer with a 200 if the JWT is valid, 401 otherwise.
It implements both JWKS (with both asymmetric RSA/ECDSA/... keys and symmetric OCT keys) and SECRET modes.
It can read jwt from headers and cookies and it can be extended to read it from anywhere (just write a sources/source.go file).
Can be used in conjunction with traefik and forwardAuth middleware (See examples/kubernetes).
You can test all the examples with something like:
curl -vv -H "Authorization: Bearer eyJraWQiOiJiZGM4N2Y2YyIsInR5cCI6IkpXVCIsImFsZyI6IkVTMjU2In0.eyJzdWIiOiJEaW1pdHJ5IiwiYXVkIjoiUnVzbGFuIiwiaXNzIjoiandrcy1zZXJ2aWNlLmFwcHNwb3QuY29tIiwiaWF0IjoxNjM5MTc4NTIyfQ.h9l2jd_kV33NQ8ygqsqAyi0iwhR_8bTp8fObRhB-BJ1xkItA2VIb135ww1BNmzMaL4Hs6FO553oJkmfwnYhx-Q" localhost:8080
docker run --rm -ti -e JWKS_URL='https://jwks-service.appspot.com/.well-known/jwks.json' -e JWKS_REFRESH_UNKNOWN_KID=false -p 8080:8080 ghcr.io/bennesp/jwt-forward-auth:latest
# docker-compose.yaml
services:
jwt:
image: ghcr.io/bennesp/jwt-forward-auth:latest
ports:
- "8080:8080"
environment:
- JWKS_URL='https://jwks-service.appspot.com/.well-known/jwks.json'
and docker-compose up -d
ADDRESS
(default is:8080
): address where the http server will listen toLOG_LEVEL
(default isinfo
): one between trace, debug, info, warn or warning, error, fatal, and panicCLAIM_MAPPINGS
(default issub:x-jwt-user-id,iss:x-jwt-issuer
): a comma separated list of claim mappings, where the first one is the claim name in the JWT and the second one is the header name to be used in the http response
HEADER_JWT_SOURCE_ENABLED
(default istrue
): If true, header source is enabledHEADER_JWT_SOURCE_NAME
(default isAuthorization
): Name of the header whose value is the jwtHEADER_JWT_SOURCE_PREFIX
(default isBearer
): If the value of the header is prefixed by a value, specify it with this environment variable so that it will be trimmed. If a value is specified but it is not found in the header, no errors will be thrown and no value will be trimmed.
COOKIE_JWT_SOURCE_ENABLED
(default isfalse
): If true, cookie source is enabledCOOKIE_JWT_SOURCE_NAME
(default istoken
): Name of the cookie whose value is the jwt
JWKS_ENABLED
(default istrue
): If true, validation with JWKS is enabledJWKS_URL
(default is""
): URL of the keys of your IdP. For example https://jwks-service.appspot.com/.well-known/jwks.jsonJWKS_REFRESH_INTERVAL
(default is1h
): Interval between the refresh of the keys. Disable setting it to 0.JWKS_REFRESH_RATE_LIMIT
(default is5m
): Rate limit for the refresh of the keys. Max refresh interval (ifJWKS_REFRESH_UNKNOWN_KID
is true). Does not make sense to haveJWKS_REFRESH_INTERVAL
shorter than this.JWKS_REFRESH_TIMEOUT
(default is5s
): Timeout for the refresh of the keys.JWKS_REFRESH_UNKNOWN_KID
(default istrue
): If true, unknown kid will be refreshed.
JWT_SECRET_ENABLED
(default isfalse
): If true, validation with a secret is enabledJWT_SECRET
(default is""
): Secret used to sign and verify the JWT.