Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid API key when using Enterprise #414

Open
ephracis opened this issue Jun 30, 2022 · 5 comments
Open

Invalid API key when using Enterprise #414

ephracis opened this issue Jun 30, 2022 · 5 comments

Comments

@ephracis
Copy link

Hi,

I am trying to figure out how to configure this gem for Enterprise reCaptcha.

First issue I ran into was that it seems like one needs to specify config.site_key, even when using enterprise. Should this be the same as config.enterprise_api_key? If so, it seems weird to specify the same data twice.

Next issue is that my recaptcha_reply states:

{
  "error"=>{
    "code"=>400, 
    "message"=>"API key not valid. Please pass a valid API key.", 
    "status"=>"INVALID_ARGUMENT", 
    "details"=>[
      {
        "@type"=>"type.googleapis.com/google.rpc.ErrorInfo", 
        "reason"=>"API_KEY_INVALID", 
        "domain"=>"googleapis.com", 
        "metadata"=>{
          "service"=>"recaptchaenterprise.googleapis.com"
        }
      }
    ]
  }
}

I have tried using both the name of the key (that I chose), and the key ID (which was generated and is used in Googles example JS snippet), but I get the same error for both: Invalid API key.

Any ideas?

@grosser
Copy link
Collaborator

grosser commented Jul 1, 2022

seems like it's supposed to be a different key

      @site_key = ENV['RECAPTCHA_SITE_KEY']

... idk how this is supposed to work, please check other issues, the wiki or possibly the setup guide for other languages on where these come from

@matheusazzi
Copy link

matheusazzi commented Jul 7, 2022

@ephracis I was having the same problem. This worked for me.

  • config.site_key is the Recaptcha Enterprise key you see at your Recaptcha console.
  • config.enterprise_api_key has nothing to do with Recaptcha, it's an enterprise key of your Google Cloud Project, you should see it at https://console.cloud.google.com/apis/credentials.

This is the request the gem makes:

POST https://recaptchaenterprise.googleapis.com/v1/projects/ENV["RECAPTCHA_ENTERPRISE_PROJECT_ID"]/assessments?key=ENV["RECAPTCHA_ENTERPRISE_API_KEY"]

Body:
{
  "event": {
    "token": "TOKEN",
    "siteKey": ENV["RECAPTCHA_SITE_KEY"],
    "expectedAction": "USER_ACTION"
  }
}

@thadeu
Copy link

thadeu commented Aug 21, 2023

Even if using the RECAPTCHA_SITE_KEY as credentials, I received error

@joshh20
Copy link

joshh20 commented Apr 3, 2024

@ephracis I was having the same problem. This worked for me.

  • config.site_key is the Recaptcha Enterprise key you see at your Recaptcha console.
  • config.enterprise_api_key has nothing to do with Recaptcha, it's an enterprise key of your Google Cloud Project, you should see it at https://console.cloud.google.com/apis/credentials.

This is the request the gem makes:

POST https://recaptchaenterprise.googleapis.com/v1/projects/ENV["RECAPTCHA_ENTERPRISE_PROJECT_ID"]/assessments?key=ENV["RECAPTCHA_ENTERPRISE_API_KEY"]

Body:
{
  "event": {
    "token": "TOKEN",
    "siteKey": ENV["RECAPTCHA_SITE_KEY"],
    "expectedAction": "USER_ACTION"
  }
}

Thank you for explaining, the Google documentation completely skipped over this important detail.

@grosser
Copy link
Collaborator

grosser commented Apr 4, 2024

if the readme can be clearer about that, please make a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants