Google cloud run endpoint (extensible) service proxy api gateway firebase token

Viewed 68
# openapi2-run.yaml
swagger: "2.0"
info: # >1 API/service; spec x-google-api-name OpenAPI document extension.
  title: backbank # mastercard-backbank # API_ID optional-string
  #https://cloud.google.com/api-gateway/docs/get-started-cloud-run
  description: node cloud run api mastercard p.12 customer keys # Sample API on API Gateway with a Cloud Run backend
  version: 0.0.1
security:
  - firebase: []
securityDefinitions: #https://cloud.google.com/api-gateway/docs/authenticating-users-firebase
  firebase: #bearer https://cloud.google.com/endpoints/docs/openapi/openapi-extensions
    authorizationUrl: "" # empty for firebase frm bearer Authorization?
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "https://securetoken.google.com/vaumoney"
    x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
    x-google-audiences: "vaumoney"
host: "vault-co.in"
basePath: "/" # https://stackoverflow.com/questions/71258737/making-a-cloud-firestore-rest-api-call-through-cloud-endpoints
#When the basePath property is configured in the service configuration as well,
#this header applies only to URL paths that are prefixed by the basePath property value.
#URLs that aren't part of the basePath aren't passed through regardless of the x-google-allow property.

schemes:
  - https
consumes:
  - application/json
produces:
  - application/json
#x-google-allow:
  #all
  #jwt_audience: https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com/vaumoney
#x-google-endpoints:
  #- name: "vault-co.in"
    #allowCors: True
paths:
  /:
    get:
      summary: Yes Hello cloud run (api gateway, load balance) service
      operationId: get
      x-google-backend: 
        address: https://vault-co.in:8080 # APP_URL endpoint(s)
        protocol: h2
      responses:
        200:
          description: This is a (Non-Graphical) Application Programming Interface
          #schema:
          #type: string
          #default: '''ello guv'''

        default:
          description: Something is wrong
          #schema:
          #type: string
          #default: '''some not 200'''

    options:
      summary: Enable CORS with headers
      operationId: options
      x-google-backend:
        address: https://vault-co.in:8080 # APP_URL endpoint(s)
        jwt_audience: https://vault-co.in 
        protocol: h2
      description: |
        Origin, Methods and Headers allowing headers potentially requested
      tags:
        - CORS
      responses:
        200:
          description: OPTIONS responding headers
          headers:
            Access-Control-Allow-Origin:
              type: string
              #$ref: '#/definitions/String'
              default: "'i7l8qe.csb.app'"
            Access-Control-Allow-Methods:
              type: string
              default: "'GET,POST'"
            Access-Control-Allow-Headers:
              type: string
              default: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
        403:
          description: OPTIONS responding headers
          headers:
            Access-Control-Allow-Origin:
              type: string
              default: "'i7l8qe.csb.app'" # '''vau.money'''
            Access-Control-Allow-Methods:
              type: string
              default: "'GET,POST'"
            Access-Control-Allow-Headers:
              type: string
              default: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
          #content: {}

        default:
          description: Something is wrong
          #type: string
          #default: '''some not 200'''

    post:
      summary: Respond properly indeed
      operationId: posted
      x-google-backend:
        address: https://vault-co.in:8080 # APP_URL endpoint(s)
        jwt_audience: https://vault-co.in 
        protocol: h2
      description: |
        Successful api fetch
      parameters:
        - name: pageOffset
          in: body
          required: true
          schema:
            type: object
            properties:
              pageOffset:
                description: pageOffset is required, try 0
                type: string
              pageLength:
                description: pageLength is required, try 10
                type: string
              postalCode:
                description: postalCode is required, try 11101
                type: string

      responses: # https://swagger.io/docs/specification/describing-responses/
        default: #200
          description: post result
          #content:v3 application/json:
          schema:
            type: object
            description: response ok
            required:
              - results
            properties:
              results:
                #collectionFormat: csv
                type: array
                default: []
                items:
                  type: string
              meta:
                type: object
                properties:
                  title:
                    type: string
                  description:
                    type: string

I repeat attempts in seriatim:

  1. gcloud api-gateway gateways delete backbank --location=us-central1
  2. gcloud api-gateway api-configs delete backbank --api=backbank
  3. gcloud api-gateway api-configs create backbank --api=backbank --openapi-spec=swagger.yaml --project=vaumoney --backend-auth-service-account=vaumoney@appspot.gserviceaccount.com
  4. (a) gcloud endpoints services deploy swagger.yaml --project=vaumoney (b) gcloud services enable vault-co.in (Principal-role permission name: "firebase-adminsdk")
  5. gcloud run deploy backbank \ --image="gcr.io/vaumoney/endpoints-runtime-serverless:2.38.0-vault-co.in-2022-09-08r2" \ --set-env-vars ESPv2_ARGS=^++^--cors_preset=cors_with_regex++--cors_allow_origin_regex=^https:[/][/]i7l8qe.csb.app$++--cors_allow_methods=GET,POST,OPTIONS++--cors_allow_headers=Origin,Content-Type,Authorization,Referrer-Policy++--cors_allow_credentials \ --platform managed --project vaumoney

Of course, I incessantly get this:

The request was not authenticated. Either allow unauthenticated invocations or set the proper Authorization header. Read more at https://cloud.google.com/run/docs/securing/authenticating Additional troubleshooting documentation can be found at: https://cloud.google.com/run/docs/troubleshooting#unauthorized-client

But OPTIONS might be the problem (albeit "" on GET):

"This would be really useful for us, we're using cloud run for all our microservices and want to call these from a SPA via API Gateway." "We're back to Cloud Endpoints and ESPv2 for the time being, but we 100% see the benefits of the managed API Gateway, should CORS support be available for gRPC requests."

What am I to do?

0 Answers
Related