How to perform domain verification for Firebase functions
Asked Answered
B

2

13

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.

Butyraldehyde answered 4/4, 2018 at 22:30 Comment(0)
C
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.

Chantel answered 27/4, 2018 at 7:36 Comment(2)
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.Weig
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?Heteronomy
F
9

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

Frostwork answered 12/7, 2019 at 12:9 Comment(3)
You saved my day!Wellinformed
Considering general Cloud Functions (not firebase), just changed declaration to: exports.googleDomainVerification = (req, res) => { ...Shelving
@Frostwork 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.netPoet
C
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.

Chantel answered 27/4, 2018 at 7:36 Comment(2)
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.Weig
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?Heteronomy

© 2022 - 2024 — McMap. All rights reserved.