21

I'm using Firebase Authentication for my web app, and customizing the redirect domain for Firebase Authentication's Google Sign-In feature so that Google's authentication page will

show Continue to: https://auth.mydomain.com,

instead of Continue to: https://my-app-12345.firebaseapp.com.

So I did four steps according to instructions on Firebase's documentation:

(1) Create a CNAME record for auth.mydomain.com that points to my-app-12345.firebaseapp.com

(2) Add auth.mydomain.com to the list of authorized domains in the Firebase console

(3) In the Google OAuth setup page, whitelist the URL of the redirect page which is https://auth.mydomain.com/__/auth/handler

(4) Edit my app's JavaScript code which initializes Firebase library:

var config = {
  ...
  // from 'authDomain: my-app-12345.firebaseapp.com,'
  authDomain: 'auth.mydomain.com',
  ...
};

After that, however, when my app invokes firebase.auth().signInWithRedirect(provider) method, web browser will show privacy warning like the following:

Your connection is not private

Attackers might be trying to steal your information from auth.mydomain.com (for example, passwords, messages, or credit cards). Learn more

NET::ERR_CERT_COMMON_NAME_INVALID

...

This server could not prove that it is auth.mydomain.com; its security certificate is from firebaseapp.com. This may be caused by a misconfiguration or an attacker intercepting your connection.

Proceed to auth.mydomain.com (unsafe)

And certificate information is as follows:

firebaseapp.com

Issued by: Google Internet Authority G3

Expires: Tuesday, 13 November 2018

This certificate is valid.

Details

Subject Name

Country: US

State/Province: California

Locality: Mountain View

Organization: Google Inc

Common Name: firebaseapp.com

And below is URI:

https://auth.mydomain.com/__/auth/handler?apiKey=apiKey&appName=%5BDEFAULT%5D&authType=signInViaRedirect&providerId=google.com&scopes=profile&redirectUrl=https%3A%2F%2Fwww.mydomain.com%2Flogin&v=5.0.4

Why does customizing the redirect domain for Google Sign-In prompt NET::ERR_CERT_COMMON_NAME_INVALID warning, and how should I do to avoid the warning message from prompting, e.g. adding Subject Alternative Names into the certificate, using auth.mydomain.com's own certificate?

By the way, in the above warning page, if Proceed to auth.mydomain.com (unsafe) is clicked, authentication will work as expected.

2 Answers 2

47

Because auth.mydomain.com points to my-app-12345.firebaseapp.com via CNAME record, host of firebaseapp.com should provision SSL certificate for auth.mydomain.com. It has to be done in Firebase Hosting page even if my-app-12345 is not using Firebase Hosting. Here is step-by-step method for doing that based on Firebase's documentation:

  1. In Firebase project my-app-12345's console, click Hosting on the side menu.
  2. When Set up hosting pop-up appears, click Continue. Then click Finish.
  3. In Hosting page, click Connect domain.
  4. When Connect domain pop-up appears, enter auth.mydomain.com. Then click 'Redirect auth.mydomain.com to an existing website' checkbox. Then enter my-app-12345.firebaseapp.com. Then click Continue.
  5. When 'Add the TXT records below to your DNS provider to verify you own mydomain.com' pop-up appears, follow the instruction. And click Verify. (Verifying may take some minutes). Then click Finish.

Now auth.mydomain.com will be appeared in domain section with Pending status. It will soon be changed to Connected. And after some time, the NET::ERR_CERT_COMMON_NAME_INVALID warning issue will be gone.

P.S. With help of Firebase technical support team, I have got the answer to my own question.

6
  • 1
    The firebase doc is not clear about cname and SSL problem, but this steps are just that I needed
    – Diego
    Dec 3, 2018 at 22:01
  • Thanks @sortofimport! Do you still have to use the CNAME after adding the TXT record? plus if your not using my-app-12345.firebaseapp.com but my-app-12345.mydomain.com do you have to use that as the 'existing website'? Aug 28, 2019 at 22:20
  • @Stevie-Ray Hartog, (1) Yes, I had to use CNAME even after adding TXT. (2) I didn't try to use my-app-12345.mydomain.com instead of my-app-12345.firebaseapp.com. Aug 31, 2019 at 1:56
  • Wow! Thanks a ton. This should seriously have been a part of the docs :) Jul 20, 2020 at 9:42
  • 2
    Thanks, this worked for me (despite of @morespamforya's answer below).
    – gamliela
    Jul 25, 2020 at 5:43
12

just to clarify, as of Jan 6th 2020, the method above (using 'Redirect' within Firebase Hosting) doesn't work anymore.

Following something written in https://levelup.gitconnected.com/how-to-connect-a-domain-to-your-firebase-project-cd47373bad79 - we can see for Authentication, we need to use "Custom Domains" and not "Redirect"

This is because if redirection is used, the SSL signed between the exit and entry points of the custom domain and Google's authentication servers will fail the handshake.

In other words:

If you are setting it up for the first time:

  1. In Firebase project my-app-12345's console, click Hosting on the side menu.

  2. When Set up hosting pop-up appears, click Continue. Then click Finish.

  3. In Hosting page, click Connect domain.

  4. When Connect domain pop-up appears, enter auth.mydomain.com. Then do not tick 'Redirect auth.mydomain.com to an existing website' checkbox. Then enter my-app-12345.firebaseapp.com. Then click Continue.

If you've already setup a Redirect domain, and you cannot get it to work - you can simply edit the entry, and change to a "Custom" type.

Wait 10 ~ 30 minutes once that has changed to have this function properly.

5
  • 1
    Hello, I am looking at this issue and it seems that we need to host the app on Firebase for this to work? Am I missing something? I have my frontend hosted on netlify, using firebase for auth. But all the steps I am reading seem to want me to move my app to firebase hosting by pointing my domain to Firebase? Is this why you need to create a subdomain for authentication, like auth.mydomain.com? And how does that work with localhost?
    – Kev
    Jan 6, 2020 at 11:04
  • Yes it would appear so - this is because Firebase (or Google) servers need to act as an entry point to ensure that the SSL certificates exchanged are properly signed by Google. I don't think the Firebase hosting element of this actually costs money (i.e. you can do this on a free account to test this theory) Jan 6, 2020 at 22:06
  • 1
    I had the same issue and was able to fix it based on this answer. Please note that Google is able to provide the SSL certificate by using the CNAME redirect, so you don't (and in fact can't) add an A record pointing to the Firebase IPs.
    – Felipe
    May 9, 2020 at 19:46
  • 1
    I can only either choose redirect or adding a custom domain, where do you enter my-app-12345.firebaseapp.com then?
    – M0rph3v5
    Dec 1, 2020 at 17:41
  • If we don't tick the redirect checkbox, where should we enter my-app-12345.firebaseapp.com? Apr 19, 2021 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.