Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express Gateway JWT issue

I'm using express gateway as an API gateway. I want EG (Express Gateway) to authenticate JWTs that my keycloak server will sign. My setup in gateway.config.yml is like this:

http:
  port: 6060
admin:
  port: 9876
  hostname: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/ip'
serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
policies:
  - basic-auth
  - jwt
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  default:
    apiEndpoints:
      - api
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
      - jwt:
          secretOrPublicKey: MySuperSecretKey
      - proxy:
          - action:
              serviceEndpoint: httpbin 
              changeOrigin: true

I'm starting EG server, and then I'm going to https://jwt.io/ selecting HS256 setting the payload, and secret key and a JWToken is generated. Then I'm making a request with postman using bearer token as it is the default and I'm getting 401 unauthorized.

Does anyone have any idea what I'm doing wrong with the configuration?

like image 806
Rambou Avatar asked Mar 04 '26 22:03

Rambou


1 Answers

with the current configuration you're required to create an internal credential JWT credential so that Express Gateway can look for the token and check it accordingly.

In case you want to skip this check, just set the checkCredentialExistence to false as a jwt policy parameter. The request will then pass.

Cheers!

like image 74
Vincenzo Avatar answered Mar 08 '26 21:03

Vincenzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!