How to perform domain verification for Firebase functions

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 :)


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.