Home > front end >  Authentication problem with google cloud function gen2 in golang on firebase routing
Authentication problem with google cloud function gen2 in golang on firebase routing

Time:01-21

Im testing go gen2 google cloud functions, the code of the function was deployed ok, it works ok, everything is fine. The function is named readrequest, and it is open to everybody. You can reach it https://readrequest-v7disnxdea-uc.a.run.app

I also add mapping to a dedicated subdomain without problem.

Now I'm trying to route in one web firebase app. For that I've added a route to firebase.json

the rules in firebase.json looks like:

{
  "hosting": {
    "public": "public",
    "rewrites": [

      {
        "source": "/l",
        "function": "l3"
      },
      {
        "source": "/gotest",
        "function": "readrequest"
      },
      {
        "source": "/gotest/**",
        "function": "readrequest"
      },
      {
        "source": "/rc1",
        "function": "rc1"
      },
      {
        "source": "/rc2",
        "function": "rc2"
      },
      {
        "source": "/rc2/**",
        "function": "rc2"
      },
      {
        "source": "/rc1/**",
        "function": "rc1"
      }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

I can reach the funcion, always ask for authentication, but it doesn't work even if I accept to authenticate. I've created the function in us-central1 to avoid problems.

The error is:

Error: Forbidden
Your client does not have permission to get URL /readrequest/gotest/asdf from this server.

If I misspell the function name I get the same error, so it is like the router isn't locating the function, but don't why not.

CodePudding user response:

Because Cloud Functions gen2 runs on top of Cloud Run (url, permission, logs, and many other things are the same!), the way to reach Cloud Functions gen2 is not the usual Cloud Functions gen1 manner, it's the Cloud Run one!

Buy the way, replace the function (gen1) reference "function": "readrequest", the functions (gen2, i.e. Cloud Run) reference "run": { "serviceId": "readrequest", "region": "us-central1" }

  • Related