Express Gateway JWT 问题

Express Gateway JWT issue

我正在使用快速网关作为 API 网关。我希望 EG(Express Gateway)验证我的 keycloak 服务器将签名的 JWT。我在 gateway.config.yml 中的设置是这样的:

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

我正在启动 EG 服务器,然后我将 https://jwt.io/ 选择 HS256 设置有效负载,然后生成密钥和 JWToken。然后我使用不记名令牌向邮递员发出请求,因为它是默认设置,我得到 401 未经授权。

有人知道我在配置上做错了什么吗?

使用当前配置,您需要创建内部凭据 JWT 凭据,以便 Express Gateway 可以查找令牌并进行相应检查。

如果您想跳过此检查,只需将 checkCredentialExistence 设置为 false 作为 jwt 策略参数。然后请求将通过。

干杯!