69

I imported Firebase JS v3 API and used to initialize Firebase using:

firebase.initializeApp(config);

However the app failed to load correctly via web browser on localhost, resulting in the following error:

Error: This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.

firebase.js:71:1333

user6039980
  • 3,108
  • 8
  • 31
  • 57

13 Answers13

69

I solved the problem by adding the localhost domain to OAuth redirect domains (within SETUP SIGN IN METHOD on the Auth tab of Firebase console).

Updated: Aug 14 2023 - Now the Authorized domains section is moved to settings on the Authentication tab of Firebase console.

user6039980
  • 3,108
  • 8
  • 31
  • 57
  • 8
    Ohhh they moved this setting into the "Sign in method" subsection of the "Auth" section. Thanks! – Liron Shapira May 21 '16 at 22:15
  • Does it work instantly? I am using a fake local domain set up in my hosts file like myapp.localdevmachine.com. I added it with and without the subdomain part to the firebase console in the OAuth redirect domains but I still get the Unauthorized Request Origin error in the popup. It doesn't matter which provider I use they all come back to that error. I set it up about 1 hour ago and it still fails. I have also localhost, and 127.0.0.1 added to the domains. – JavierLerones May 26 '16 at 00:16
  • @JavierLerones If have you made **all the required steps** (https://firebase.google.com/support/guides/firebase-web) for upgrading to the new Google API, then yes it should work. – user6039980 May 26 '16 at 14:24
  • what means "using localhost instead of 127.0.0.1 inside a different web browser"? how it relates to ionic app configuration? – ciekawy Jun 30 '16 at 17:25
  • @ciekawy I think it was a connecting issue to port 8100. see also http://stackoverflow.com/questions/30029532/ionic-serve-starts-on-localhost-and-not-the-server-ip. – user6039980 Jul 11 '16 at 08:35
  • 1
    Ah so it's not about real device... I've never experienced the problem locally and thought your issue was concerning device/simulator – ciekawy Jul 11 '16 at 08:38
  • you can add 127.0.0.1 to authorized domains - box shows red invalidated but it will still allow you to add it in the add domain section of firebase authentication – Tom22 Oct 13 '17 at 16:33
  • my website was live so i didnt had localhost, it worked by copying all the websites from firebase auth authorized domains to google cloud platform - api and services - credentials - browser key - website restriction filter – codmitu Jun 08 '23 at 15:38
61

in firebase console Auth --> Authorised domains

enter image description here


must equal (in Google cloud console -- > API & Services --> credentials ) :

enter image description here


must equal (in api config) :

enter image description here

Suliman Farzat
  • 1,197
  • 11
  • 12
14

Solution which worked for me after trying out all the options on the listed above and on other sites regarding using FireBase oAuth was the following:

  1. login at https://console.cloud.google.com
  2. Go to APIs & Services > Credentials

enter image description here

Once here, locate API Key you are using in your app that connects to FireBase

  1. Now add your custom domain to HTTP Referrers

enter image description here

enter image description here

For android or ios or having your application on all three mediums, you will need to create API keys per medium.

isawk
  • 969
  • 8
  • 21
  • 2
    Additional fixes for some here https://github.com/angular/angularfire2/issues/1444, it appears that for each domain added to FireBase Security Auth Section must also manually get added to Google Console APIs and Services – isawk Jan 28 '18 at 04:09
  • My man! Thanks so much. This is what I was looking for. – KJ Sudarshan Jun 20 '21 at 10:57
12

Make sure the "authDomain" in your config matches the one in your firebase console. If you're running the app on localhost, make sure it's set to localhost and localhost exists on your firebase console.

Auth -> Sign In Method -> OAuth redirect domains

var config = {
    apiKey: "...",
    authDomain: "...", // this should match the one on your firebase console
    databaseURL: "...",
    storageBucket: "",
};
firebase.initializeApp(config);
TheAppchemist
  • 514
  • 3
  • 14
  • 1
    Mine matches, yet I still get the error: Uncaught Error: An internal error has occurred. – KhoPhi Jun 10 '16 at 20:43
  • I traced down the error message down to the point that, my api key expired was the culprit. I have no idea why it expired. But got it resolved. – KhoPhi Jun 12 '16 at 14:32
6

Firebase Users

For me the source of the error was that the domain was not added in the firebase console. Here is an image in the firebase console to add the custom domain for your website: firebase console

atb00ker
  • 957
  • 13
  • 24
6

Firebase now has localhost as Authorized domains by default but if you are facing this for a custom domain, here is a quick solution.

  • Go to Google console Authentication tab > Settings > Authorized domains
  • Add your domain

enter image description here

(PS - About version, I'm using Firebase 9.9.3 on React.)

Shubham Sarda
  • 539
  • 5
  • 10
3

Problem Authorised domain Firebase Locahost OAUTH2

If you are using Google Chrome you can see a problem with the Identity Toolkit API DISABLE. You need to enabled this API on the google cloud project to get OAUTH servcies in Firebase project.

https://console.developers.google.com/apis/api/identitytoolkit.googleapis.com/overview?project=project-id

1

Not really specific to Android, but check the address in your actionCodeSettings.

actionCodeSettings.url must be correct and whitelisted.

Authenticate with Firebase Using Email Link in JavaScript

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91
1

For those having this issue in Heroku:

Make sure you keep the authDomain property with the same value you got from Firebase.

DO NOT change this to the current Heroku domain.

Roberto Rodriguez
  • 3,179
  • 32
  • 31
1

None of the above answers worked for me, as I already had localhost in Authorized domains list. For me the problem was incorrect API key, I must have somehow deleted one of the characters from it. I got a more descriptive (or rather - not misleading) error message when I changed to signInWithPopup to signInWithRedirect. Possibly the same problem might happen when the API key is expired.

sloneorzeszki
  • 1,274
  • 3
  • 12
  • 22
1

None of the above solutions worked for me but this did.

  1. Go to Google console Authentication tab > Sign In Method > Authorized Domains
  2. Add 127.0.0.1

localhost was already in my Authorized Domains but in my case I needed to add 127.0.0.1 as well

nth-child
  • 402
  • 8
  • 15
0

The important point is.. you must add the yourprojectid.firebaseapp.com domain to the authorized domains.. not your real domain name. That worked for me.

Kishore
  • 29
  • 1
  • 4
0

I got this problem also and the domain was like this: 127.0.0.1:5173/ I just turned it into: localhost:5173 and it ran without a problem.

Walid Sahnoun
  • 44
  • 2
  • 5