Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: Forbidden Your client does not have permission to get URL /api/app from this server

I'm having trouble accessing a JSON api that is inside of my Firebase account. I'll type "firebase deploy" in my terminal and it'll return the following url,

https://myProjectID.firebaseapp.com

If I then enter it into my browser I get my Index.html page so I know it generally works. But being that I'm trying to access the API I search the URL/api/app which works when I run "firebase serve" but doesn't when I run deploy. It returns the following

ERROR: Forbidden Your client does not have permission to get URL /api/app from this server

however my gmail account is permitted on firebase and everything checks out but firebase & cloud functions still won't let me access my API. Please help.

This is my code.

INDEX.JS

const functions = require("firebase-functions");
const server = require(__dirname,"../server.js");
const api = functions
  .runWith({ memory: "2GB", timeoutSeconds: 120 })
  .https.onRequest(server);

module.exports = {
  api
};

SERVER.JS

const express = require("express");
const path = require("path");
const logger = require("./middleware/logger.js");
const cors = require("cors");

const routes = require("./router/routes.js");

let app = express();

// Init Middleware
app.use(logger);

// Set static folder
app.use(express.static(path.join(__dirname, "public")));
app.use(cors({ origin: true }));
app.use("/", routes);

module.exports = app;

FIREBASE.JSON

{
  "database": {
    "rules": "database.rules.json"
  },
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "function": "server"
      }
    ]
  }
}
like image 830
RaineOxy Avatar asked Feb 23 '20 00:02

RaineOxy


People also ask

What are firebase cloud functions?

Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.

How to fix “your client does not have permission to get url/…”?

The solution was to manually add the Cloud Functions Invoker permission to the allUsers user in the Cloud Functions page in the Google Cloud Console. There are several reasons for which you are getting this error message “Your client does not have permission to get URL /… from this server” among them are:

What does it mean when it says your client does not have permission?

Your client does not have permission to get URL / from this server” “It appears you don’t have permission to access this page.” If you’re on an Nginx server, it will look like this below. Basically, if you see any mention of “forbidden” or “not allowed to access”, you’re probably dealing with a 403 Forbidden error.

Why is my website getting 403 Forbidden error?

However, if you’re hosting elsewhere and your host uses the Apache web server, one common cause of the 403 Forbidden error is a problem in your site’s .htaccess file. The .htaccess file is a basic configuration file used by the Apache web server. You can use it to set up redirects, restrict access to all or some of your site, etc.

What does it mean when it says it is forbidden?

It is an HTTP status code. When you encounter this error message, you are basically trying to reach an address or a website that is forbidden to access. Here are examples of some these errors that are commonly thrown: Forbidden: You don't have permission to access [directory] on this server


2 Answers

It must be solved at your GCP Console. Just follow these steps:

  1. Go to your GCP Console and login
  2. On the top menu, select the corresponding Firebase project
  3. On the left menu go to Cloud Functions
  4. Click the checkbox of your function (not the name of the function)
  5. Once selected, on the right menu select "Add member"
  6. On "New member" type allUsers
  7. On the Select function bar, select Cloud Functions -> Cloud functions invoker
  8. Click on "Save" and then "Allow public access" on the pop-up warning

And you're good to go!

like image 192
Omar Said López Tronco Avatar answered Oct 19 '22 04:10

Omar Said López Tronco


Searching around about it, it seems that this is an error that might occurs due to many different reasons. Usually, this is due to the way that you are authenticating on Firebase.

Considering that, I would recommend you to take a look at the following Community posts, for more information, on alternatives to fix the error.

  • Firebase cloud function “Your client does not have permission to get URL /200 from this server”
  • Error: Forbidden Your client does not have permission to get URL /az from this server

I believe one of these should help you fix your issue.

Let me know if the information helped you!

like image 2
gso_gabriel Avatar answered Oct 19 '22 04:10

gso_gabriel