GCP端点使用多重身份验证

时间:2020-05-19 19:25:38

标签: authentication firebase-authentication swagger google-cloud-endpoints

我在swagger文件中为方法定义了以下安全方案:

...
    get:
      ...
      security:
      - api_key: []
      - firebase: []
securityDefinitions:
  api_key:
    in: query
    name: key
    type: apiKey
  firebase:
    authorizationUrl: ''
    flow: implicit
    type: oauth2
    x-google-audiences: project-id
    x-google-issuer: https://securetoken.google.com/project-id
    x-google-jwks_uri: https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com

但是,如果我尝试使用api密钥发送请求,则无法使用,但是,如果我使用了Firebase令牌(即使我未提供api密钥),也无法使用。

响应:

{
    "code": 16,
    "message": "JWT validation failed: Missing or invalid credentials",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.DebugInfo",
            "stackEntries": [],
            "detail": "auth"
        }
    ]
}

如果我从安全性定义中删除了Firebase,那么它将使用api密钥运行。

如果还存在用于同一方法的oauth2,那么api密钥安全方案将无法工作是一个已知问题吗?

1 个答案:

答案 0 :(得分:1)

当替代方法之一是API密钥时,会发生“或”安全要求are not supported。因此,您正在经历正确的行为。

如果您同时提供这两种选择,则将忽略API密钥,但是如果OAuth2被删除并且仅接受API密钥,则它将起作用。

根据我附加的同一documentation,您可能需要使用“ AND”条件的两种身份验证方法。像这样:

...
security:
- api_key: []
  firebase: []
....