首页 > 解决方案 > 如何使用 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

标签: express-gateway

解决方案


推荐阅读