express-gateway - 如何使用 Oauth2.0 中的范围授权用户使用 Express Gateway(微服务 API 网关)?
问题描述
我用 key-auth 机制做的范围是完美的,但是当我使用 Oauth2.0 机制的范围时,我得到了未经授权的错误。我没有使用范围,Oauth2.0 机制运行良好。请建议如何解决这个问题?
以下是网关 YAML 配置:
http:
port: 8080
admin:
port: 9876
host: localhost
apiEndpoints:
api:
- host: 'localhost'
paths: ['/user', '/user/:id']
methods: ["GET"]
scopes: ["user"]
- host: 'localhost'
paths: ['/user', '/user/:id']
methods: ["PUT", "POST", "DELETE"]
scopes: ["admin"]
myApiRest:
host: 'localhost'
paths: '/posts'
serviceEndpoints:
jsonplaceholder:
url: 'http://localhost:8899'
restDummyService:
url: 'https://jsonplaceholder.typicode.com'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
- name: one
apiEndpoints:
- api
policies:
- oauth2:
#- basic-auth:
#- key-auth:
- proxy:
- action:
serviceEndpoint: jsonplaceholder
changeOrigin: true
- name: two
apiEndpoints:
- myApiRest
policies:
#- key-auth:
- proxy:
- action:
serviceEndpoint: restDummyService
changeOrigin: true
解决方案
推荐阅读
- dart - 如何使用“dart pub global run”命令运行脚本?
- node.js - 无法构建 Angular - “检测到 Node.js 版本 v10.6.0。”
- docker - 更新 docker 内的包是要走的路吗?
- c# - 无法在 C# 中从 {int xyz} 转换为 int
- c++ - 如何更改 QTreeView 小部件中的图标
- typescript - 从数组中提取嵌套属性
- android - 在 Delphi 10.4.2 中使用 Google Analytics GA4
- java - Java Spring Data OneToMany 关系芯片错误
- stm32 - 如何查看我的 STM32 引导加载程序的功能
- docker - 尝试使用带有 Firefox 浏览器的 Docker-compose 容器运行测试收到错误消息