我们正在将Express-gateway用于我们的微服务。我们已经使用Jwt设置了身份验证。我们要验证jwt并解码有效负载并将其设置为req params
这是我们的gateway.config.yml文件
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
user:
host: localhost
paths: "/v1/users"
product:
host: localhost
paths: "/v1/products"
serviceEndpoints:
user:
url: http://localhost:3001
product:
url: http://localhost:3000
policies:
- basic-auth
- key-auth
- cors
- expression
- log
- oauth2
- proxy
- rate-limit
- jwt
pipelines:
- name: default-1
apiEndpoints:
- user
policies:
- jwt:
- action:
secretOrPublicKey: privatekey
checkCredentialExistence: 'false'
- proxy:
- action:
serviceEndpoint: user
- name: default-2
apiEndpoints:
- product
policies:
- jwt:
- action:
secretOrPublicKey: privatekey
checkCredentialExistence: 'false'
- proxy:
- action:
serviceEndpoint: product
我的Jwt有效负载令牌看起来像
{
"org": "1234567890",
"siteID": "343434343",
"expiry": "600"
}
在解码并验证了jwt签名后,网关应将有效负载信息设置为req为
req.org = payload.org
req.siteId = payload.siteId
并将其传递给我们的基础微服务。这该怎么做。我是否应该在gateway.config.yml文件中设置更多参数。请指教。谢谢
您所需要做的就是从这些属性中获取这些属性req.user
-解码后的有效负载存储在此处。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句