Why: appengine to firebase Authentication fails with error referer forbidden - firebase

I have this web app project which I deploy on a google cloud appengine.
gcloud app deploy
The appengine is basically just a webserver serving static files. But I had to use the appengine for prerendring the website for SEO.
In the webapp, I use the firebase authentication API.
https://www.gstatic.com/firebasejs/7.8.0/firebase-auth.js
In firebase console, I activated the anonymous authentication.
preview of firebase auth providers
When I deploy a new version of my static content on the appengine, I create a new version named "stag" only to preview and test everything before deploying to production. I can then preview my work on the version specific url which is something like this:
https://stag-dot-frb-proj1.appspot.com/
frb-proj1: is my firebase project id.
When I preview my work on the url: https://stag-dot-frb-proj1.appspot.com/
I got the following error:
{
"error": {
"code": 403,
"message": "Requests from referer https://stag-dot-frb-proj1.appspot.com/ are blocked.",
"errors": [
{
"message": "Requests from referer https://stag-dot-frb-proj1.appspot.com/ are blocked.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
I spotted the error in the chrome dev tools on the network tab. It happens when the app tries to access the following url:
https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIza....CcpT0
I assume this api call if for creating a new anonymous user on the firebase auth api.
All the used domains are authorized in the firebase console as expected.
Authorized DOMAINS
frb-proj1.firebaseapp.com
frb-proj1.web.app
stag-dot-frb-proj1.appspot.com
frb-proj1.appspot.com
Tried solution
I tried to follow this example https://cloud.google.com/appengine/docs/standard/python/authenticating-users-firebase-appengine
And setup the environment variable FIREBASE_PROJECT_ID in my app.yaml for the appengine
QUESTION
Any idea what is wrong ?

Considering this error, it seems that this problem is related to your API Key. As per these other similar cases - that you can access in the below links - it seems that the API Key configured doesn't have all the needed permissions.
I would recommend you to take a look at the below cases and give it a try on the solutions informed there - all of them informed that it solved their problems.
Requests for referrer are blocked when trying to sign in anonymously to Firebase
firebaseui Internal error: {"error":{"code":403,"message":"Requests from referer are blocked.","errors":{"message":"Requests from referer
App hosted on firebase does not have access to firebase authentication? PERMISSION_DENIED
Let me know if the information helped you!

Related

Electron App: How to authorize domain on Firebase

In my electron app, I have integrated the firebase google sign-in authentication method. This method is working properly in the local environment. But after packaging the application (for Linux environment), I am getting an error 'Error while login into Gmail account FirebaseError: Firebase: Error (auth/unauthorized-domain)'. When I tried to find the cause of this error, I found that we have to add the respective domain to the authorization tab but the firebase app domain is already added in settings. As you can see in the screenshot
What else do I need to add here in the domain setting?

Question regards firebase restrictions to api key

I set up restrictions to my Firebase api key so that only my website and localhost can access to Firebase services but I've got a question.
Let's say that for testing purposes I want to call an endpoint from Postman, how can I setup restrictions so that I can call Cloud functions from postman?
Everything works from localhost and the website but when I try to call an endpoint from Postman it gives me this error:
{
"message": "Firebase: Error (auth/requests-from-referer-<empty>-are-blocked.)."
}
Ok apparantly only few routes work, the login gives me no errors meanwhile the signup route gives me the same error you see above, I don't know why...I set up restrictions such every subroute of my site can access the Firebase products

Firebase Google Auth: Getting 'The identity provider configuration is disabled' even though it is enabled

I'm getting 'The identity provider configuration is disabled' from Firebase Google Authorization even though it is clearly enabled in the Firebase console. It doesn't happen for all Google accounts.
Is anyone aware of any other reasons why this error message would be the response from the Firebase Authorization server? This is a web-app.

Running Firebase web SDK under phantomjs fails to authenticate valid tokens (auth/network-request-failed)

I am trying to use phantomJS to create a pdf of a authenticated part of a Firebase web app.
The set up is as follows
A cloudFunction is triggered when firestore is updated.
The cloudFunction creates a custom token with admin.auth().createCustomToken with the relevant claims.
A url to the hosted firebaseapp app is created, with the token as a query param.
The URL is given to phantomjs to create a pdf of the page.
When the firebase webapp boots, it grabs the token, and uses firebase.auth().signInWithCustomToken
On success it renders the page.
The hosted page works fine, and I can grab the token that the cloudFunction creates, add it to the URL and test it all in chrome with no issue.
However, when running this under phantomJS, the call to admin.auth().createCustomToken fails with
auth/network-request-failed .
A network error (such as timeout, interrupted connection or unreachable host) has occurred.
I have tried the following
Setting '--ignore-ssl-errors=yes', '--ssl-protocol=tlsv1', '--web-security=false' on PhantomJS
Setting Access-Control-Allow-Origin * on the hosting firebase.json rules
Setting a Content-Security-Policy for all the google apis on the hosting firebase.json rules
Does anyone know what would be blocking the google api within phantom?
Could it be the User agent?

Firebase: Local Development and testing in AngularFire

I am using Angularfire to make a website. I am trying to integrate oauth based sign in with google for user authentication but when I try to run index.html file and try to login following error is displayed
11:59:28.189 Error: There are no login transports available for the requested method.
Stack trace:
Mg#file:///G:/Project/root/js/firebase.js:142:1267
dh/<#file:///G:/Project/root/js/firebase.js:163:141
1 app.js:31:4
I searched on stackoverflow for this and got this answer , it says that I need to setup a server for this.
Then I looked at firebase docs and they said
For security reasons, if you're using a web-based OAuth flow
(Facebook, Twitter, Github, or Google), only domains that you
whitelist are allowed to initiate authentication for your app. This
does not apply to Email & Password, Anonymous, or Custom
authentication methods. All Firebase applications have localhost and
127.0.0.1 enabled by default for local development and testing.
The authentication works fine after I host it on firebase but deploying takes a lot of time and also sometimes even I don't have access to internet.
So please suggest me easiest manner so I can run my app on localhost.
An easy way to locally run a Firebase (or any other) web site is to use the Firebase tools and then run
firebase serve
See this blog post introducing the local server.

Resources