12

I'd like to use Google's Webmaster Tools to add domain verification for my "site", which is entirely made up of Cloud Functions for Firebase:

https://us-central1-<project-id>.cloudfunctions.net/

However I cannot figure out how to do this in a way that would work successfully.

The recommended way is to download and serve an HTML file with a verification key. However, I cannot seem to create a function with a dot.

exports['googleKEY.html'] = functions...

This fails when trying to deploy.

An alternative is to put a meta tag in my "homepage", but that also does not work as I cannot seem to create an index page.

exports[''] = functions...

and

exports['index.html'] = functions...

Also fail.

Is there a way to do this domain verification just through functions? I'd appreciate guidance.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Nick Felker
  • 11,536
  • 1
  • 21
  • 35

2 Answers2

8

I had the same problem: I wanted to validate my Domain Ownership in the Google Search Console. But the domain is actually a Firebase Cloud Functions domain (https://*.cloudfunctions.net). I found a super easy solution today:

1) When adding a property in Google Search Console, select the method "URL prefix" and enter the url of the function you will create in step 3 (i.e. https://foobar.cloudfunctions.net/googleDomainVerification).

2) Select the method "HTML tag" and copy the meta-tag.

3) Create a https function that you push on Firebase Cloud Function. Don't forget to copy your meta-tag from step 2:

exports.googleDomainVerification = functions.https.onRequest((req, res) => {
    res.status(200).send('<!DOCTYPE html> <html> <head> YOUR_META_TAG_HERE </head> <body> </body> </html>')
})

4) Wait a minute then press "Verify" on the Google Search Console

That's it. Everything should work now :)

Valentin
  • 5,379
  • 7
  • 36
  • 50
  • You saved my day! – Reza Sep 04 '19 at 17:10
  • Considering general Cloud Functions (not firebase), just changed declaration to: `exports.googleDomainVerification = (req, res) => { ...` – manasouza Apr 02 '20 at 23:32
  • 1
    @Valentin this works but how does this make our functions verified in the console? You cannot add domains with /function in google api console so the only kind of domain it will accept will be the TLD and you can't verify *.cloudfunctions.net – SebastianG Jul 23 '20 at 11:02
4

So... I think I finally may have a solution.

There is no direct way to verify a Firebase Functions domain (https://*.cloudfunctions.net) BUT verifying Firebase Hosting domain (https://*.firebaseapp.com) is easy (using verification file). So let's start with that.

There is a config option in Hosting to setup url rewrite to serve a Function. (Documented here)

This is a modified example config from the link above, opening url https://<your-project-id>.firebaseapp.com/covertFnBigben to invoke Function bigben.

{
  "hosting": {
    "public": "public",

    // Add the following rewrites section *within* "hosting"
    "rewrites": [
      {
        "source": "/covertFnBigben", "function": "bigben"
      }
    ]
  }
}

So after successfull verification of your Firebase Hosting domain you can use that domain to call Firebase Functions.

hKaspy
  • 127
  • 6
  • This led me to what i needed. There is also a `redirect` ability that will let you send the user to the function url. i havent fully tested for stuff like authentication to see if the parameters get sent and the redirect is allowed. – Tope Oct 06 '18 at 23:12
  • Doesn't work for me, I've setup the rewrite, verified the domain `xxx.firebaseapp.com`, but still get the same error when I try and use `xxx.firebaseapp.com/cloudFunction` - any ideas? – Bomber Mar 29 '19 at 09:34