Can't get key restriction by referrer working

422 views
Skip to first unread message

Stephen Suess

unread,
Feb 4, 2017, 10:12:27 PM2/4/17
to Google Civic Information API
I have implemented several calls to the Google Civic Info API via my site, they work fine until I attempt to add restriction based on referrer to my key. Then they stop working altogether, and throw no error of any sort. Does anyone know why this would be?

My site referer restriction looks like this (minus the quotes):


I have also tried:


which also fails.

As soon as I remove the referer restriction, it all works just fine again. Any ideas?

Cong Chen

unread,
Feb 6, 2017, 10:35:25 AM2/6/17
to Google Civic Information API
Hi Stephen,

Thanks for reaching out. Your steps look right. One thing I could think of is that the referrer of the http request may not match exactly what you typed for the API key restriction.

Could you check your http referrer and make sure there was no typo and that the referrer is listed correctly? I would recommend using the wildcards one (*.mydomain.org/*') and it can take up to a few minutes or so for everything to take effect. 

Some additional best practices for setting up API key as FYI. 

Thank you,
Cong

--
You received this message because you are subscribed to the Google Groups "Google Civic Information API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-civicinfo-api+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Cong Chen | Partner Technology Manager | cong...@google.com | 212-565-8800

This email may be confidential or privileged. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it went to the wrong person. Thanks. 

Stephen Suess

unread,
Feb 6, 2017, 10:48:50 AM2/6/17
to Google Civic Information API
Well this is really strange. I have used the pattern you suggested, and verified in my code (using chrome dev tools) that the referrer being sent is the same (at least the beginning part prior to the *). So I am a bit at a loss.

Just to reverify:

my referrer restriction is:

and my referrer (from chrome dev tools network panel) looks like this:


The only slightly odd thing (perhaps) is that this is being called from a modal popup (but the ajax loaded contents of that modal sit on my same server and domain).

Any ideas?

Thanks,

Stephen

Cong Chen

unread,
Feb 6, 2017, 10:57:22 AM2/6/17
to Google Civic Information API
Thanks Stephen. Yeah, I agree that it is very strange! If everything is set up on your server and domain ('mydomain.org'), I cannot think of a reason why it isn't working. Could you try the IP address restriction and see if that works?

Thanks,
Cong

--
You received this message because you are subscribed to the Google Groups "Google Civic Information API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-civicinfo-api+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen Suess

unread,
Mar 4, 2017, 5:14:10 AM3/4/17
to Google Civic Information API
Sorry it took me awhile to get back to this. Using the IP restriction seems to work, no idea why the referrer didn't, I checked the headers I was sending and they were correct. But whatever, it works. Thanks.

Cong Chen

unread,
Mar 4, 2017, 2:06:29 PM3/4/17
to google-civ...@googlegroups.com
Thanks Stephen! Glad to hear that. We will keep an eye if other users report the same thing.

To unsubscribe from this group and stop receiving emails from it, send an email to google-civicinfo...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Cong Chen | Partner Technology Manager | cong...@google.com | 212-565-8800

This email may be confidential or privileged. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it went to the wrong person. Thanks. 

--
You received this message because you are subscribed to the Google Groups "Google Civic Information API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-civicinfo...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages