1

I need a very secure cloud function so I'm trying to put it behind a API Gateway. The function works fine when I call it directy passing a Bearer token in header:

https://us-central1-<my-project>.cloudfunctions.net/<my-hello-function>

However I want to allow it to be used with a API token thru API Gateway (and then do something more useful than saying "hello"):

https://my-gateway-xxxxxxxx.uc.gateway.dev/v1/stats&key=<my-API-token>

When I try to call it I get:

{ "code": 404, "message": "Path does not match any requirement URI template." }

My API Gateway config file:

swagger: "2.0"
info:
  title: my-gateway
  version: "1.0.0"
basePath: "/v1"
schemes:
 - "https"
produces:
 - application/json
paths:
  /stats:
    get:
      tags:
      - "stats"
      summary: "get service stats"
      description: "Returns statistics"
      operationId: "hello_world"
      #produces:
      #- "application/json"
      parameters:
      - name: "since"
        in: "header"
        description: "Date to retrieve information"
        required: false
        type: "string"
        format: "date"
      x-google-backend:
          address: https://us-central1-<my-project>.cloudfunctions.net/<my-hello-function>
          path_translation: CONSTANT_ADDRESS
          protocol: h2
      responses:
        "200":
          description: "successful operation"
          schema:
            $ref: "#"
        "400":
          description: "Invalid datetime supplied"
        "404":
          description: "Unknown path"
      security:
      - api_key: []
securityDefinitions:
  api_key:
    type: "apiKey"
    name: "api_key"
    in: "query"
definitions:
  ApiResponse:
    type: "object"
    properties:
      code:
        type: "integer"
        format: "int32"
      type:
        type: "string"
      message:
        type: "string"

What's missing? What am I doing wrong?

0

hope you are doing well.

I am not an expert, but after reading the docs and checking your snippet again, shouldn't the name in securityDefinitions be key instead of api_key if that's what you use in the url?

my-gateway-xxxxxxxx.uc.gateway.dev/v1/stats&key=<my-API-token>

0

In order to use an API Key by passing it through the URL you have to send it as a query parameter, the way you're sending it is like trying to get into a route named stats&key= instead of stats.

Your URL must be something like:

https://my-gateway-xxxxxxxx.uc.gateway.dev/v1/stats?key=<my-API-token>

Replace the & on the key parameter with a ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.