【问题标题】:Google Cloud Endpoints secure all paths with Auth0Google Cloud Endpoints 使用 Auth0 保护所有路径
【发布时间】:2017-02-09 14:19:45
【问题描述】:

我尝试使用 security swagger 对象保护我的所有路径,使用 API 密钥可以正常工作,但我如何使用 auth0 或自定义身份验证来做到这一点?

security:
- api_key: []
securityDefinitions:
  api_key:
    type: "apiKey"
    name: "key"
    in: "query"

这不行

    x-security:
        - auth0_jwk:
            audiences:
              - "xxxxxxxxxxxxxxxx"
    securityDefinitions:
        auth0_jwk:
          # Replace YOUR-ACCOUNT-NAME with your Auth0 account name.
          authorizationUrl: "https://YOUR-ACCOUNT-NAME.auth0.com/authorize"
          flow: "implicit"
          type: "oauth2"
          x-issuer: "https://YOUR-ACCOUNT-NAME.auth0.com/"
          # Replace YOUR-ACCOUNT-NAME with your service account's email address.
          x-jwks_uri: "https://YOUR-ACCOUNT-NAME.auth0.com/.well-known/jwks.json"

或者这个

    security:
        - auth0_jwk:[
           "xxxxxxxxxxxxxxxx"
          ]
    securityDefinitions:
        auth0_jwk:
          # Replace YOUR-ACCOUNT-NAME with your Auth0 account name.
          authorizationUrl: "https://YOUR-ACCOUNT-NAME.auth0.com/authorize"
          flow: "implicit"
          type: "oauth2"
          x-issuer: "https://YOUR-ACCOUNT-NAME.auth0.com/"
          # Replace YOUR-ACCOUNT-NAME with your service account's email address.
          x-jwks_uri: "https://YOUR-ACCOUNT-NAME.auth0.com/.well-known/jwks.json"

【问题讨论】:

    标签: google-cloud-platform google-cloud-endpoints


    【解决方案1】:

    “x-security”的招摇配置对我来说是正确的。如果没有错误消息,我不确定您的问题到底是什么。但是,人们在使用 auth0 身份验证时经常犯的一个常见错误是,他们没有正确设置 JWT 签名算法。默认情况下,JWT 签名算法设置为“HS256”(对称密钥加密)。如果您需要使用“RS256”(非对称密钥加密),您需要进入应用设置页面,在高级配置下,在OAuth下,将“JsonWebToken Signature Algorithm”设置为RS256。

    【讨论】:

    • 感谢您的回答,我了解 RS256 和 HS256。我的意思是在示例中我可以使用 api 密钥保护所有定义的路径,但是当尝试使用 Auth0 保护所有路径时它不会工作。稍后我将使用日志更新我的问题。谢谢
    • 感谢您的回答,很抱歉提出问题
    【解决方案2】:

    解决方案很简单,我对我的 api 使用 express-swaggerize 并且验证不了解 x-security 并给我错误是不允许的,这是问题所在。

    对这篇文章感到抱歉

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-29
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      相关资源
      最近更新 更多