首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打开API -子路径没有安全性

打开API -子路径没有安全性
EN

Stack Overflow用户
提问于 2017-07-18 09:16:49
回答 2查看 876关注 0票数 1

我有下面的规范,

代码语言:javascript
复制
# [START swagger]
swagger: "2.0"
info:
  description: "A simple Google Cloud Endpoints API example."
  title: "Endpoints Example"
  version: "1.0.0"
# [END swagger]
# For App Engine deployments, delete the above "host:" line and remove the "# "
# from the following line. Then change YOUR-PROJECT-ID to your project id.
host: "<Hostname>"
basePath: "/"
consumes:
- "application/json"
produces:
- "application/json"
schemes:
- "https"
paths:
  "/users/{latitude}/{longitude}":
    get:
      description: List of users
      operationId: fetchusers
      produces:
        - application/json
        - application/xml
        - text/xml
        - text/html
      parameters:
        - name: latitude
          in: path
          description: Latitude component of location.
          required: true
          type: number
          format: double

        - name: longitude
          in: path
          description: Longitude component of location.
          required: true
          type: number
          format: double

      responses:
        '200':
          description: List of nearest users
          schema:
            $ref: '#/definitions/users'
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/errorModel'
      security:
        - firebase: []

  "/users":
    get:
      description: List of users
      operationId: fetchAllusers
      produces:
        - application/json
      parameters:
      - description: "users List"
        in: body
        name: message
        required: true
        schema:
          $ref: "#/definitions/echoMessage"
      responses:
        '200':
          description: List of nearest users
          schema:
            $ref: '#/definitions/users'
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/errorModel'
      security:
        - firebase: []
  "/users/search":
    post:
      description: "Search users"
      operationId: "searchusers"
      produces:
      - "application/json"
      responses:
        200:
          description: "users List"
          schema:
            $ref: "#/definitions/echoMessage"
      parameters:
      - description: "Search Criteria"
        in: body
        name: message
        required: true
        schema:
          $ref: "#/definitions/echoMessage"
      security:
        - firebase: []
  "/auth/info/googlejwt":
    get:
      description: "Returns the requests' authentication information."
      operationId: "auth_info_google_jwt"
      produces:
      - "application/json"
      responses:
        200:
          description: "Authenication info."
          schema:
            $ref: "#/definitions/authInfoResponse"
      security:
      - google_jwt: []
  "/auth/info/googleidtoken":
    get:
      description: "Returns the requests' authentication information."
      operationId: "authInfoGoogleIdToken"
      produces:
      - "application/json"
      responses:
        200:
          description: "Authenication info."
          schema:
            $ref: "#/definitions/authInfoResponse"
      security:
      - google_id_token: []
definitions:
  echoMessage:
    properties:
      message:
        type: "string"
  authInfoResponse:
    properties:
      id:
        type: "string"
      email:
        type: "string"
# This section requires all requests to any path to require an API key.
security:
- api_key: []
securityDefinitions:
  # This section configures basic authentication with an API key.
  api_key:
    type: "apiKey"
    name: "key"
    in: "header"
  # This section configures authentication using Google API Service Accounts
  # to sign a json web token. This is mostly used for server-to-server
  # communication.
  google_jwt:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    # This must match the 'iss' field in the JWT.
    x-google-issuer: "jwt-client.endpoints.sample.google.com"
    # Update this with your service account's email address.
    x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/jwk/YOUR-SERVICE-ACCOUNT-EMAIL"
    # This must match the "aud" field in the JWT. You can add multiple
    # audiences to accept JWTs from multiple clients.
    x-google-audiences: "echo.endpoints.sample.google.com"
  # This section configures authentication using Google OAuth2 ID Tokens.
  # ID Tokens can be obtained using OAuth2 clients, and can be used to access
  # your API on behalf of a particular user.
  google_id_token:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "https://accounts.google.com"
    x-google-jwks_uri: "https://www.googleapis.com/oauth2/v3/certs"
    # Your OAuth2 client's Client ID must be added here. You can add
    # multiple client IDs to accept tokens from multiple clients.
    x-google-audiences: "YOUR-CLIENT-ID"
  firebase:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    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"
    x-google-audiences: "<PROJECT-ID>"

还会有更多的服务。正如您所看到的,我已经放置了各种安全定义。对于不同的路径,我将使用不同的安全定义。默认情况下,我希望为所有路径启用api_key,但我希望对某些路径禁用此安全性-如何实现?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-17 13:34:32

我认为您应该按照以下步骤关闭特定方法的API键验证,即使您已经限制了对

  1. 在文本编辑器中打开项目的openapi.yaml文件。
  2. 在方法的定义中添加一个空的安全指令:
代码语言:javascript
复制
paths:
  "/echo":

post:

  description: "Echo back a given message."

  operationId: "echo"

  security: []

  produces:

参考资料:https://cloud.google.com/endpoints/docs/openapi/restricting-api-access-with-api-keys

票数 1
EN

Stack Overflow用户

发布于 2018-06-24 09:14:29

这很简单。

代码语言:javascript
复制
paths:
  /token:
    post:
      security: []
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45162453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档