FireBase Recaptcha verification failed - SITE_MISMATCH

lor*_*ock 5 python firebase firebase-authentication

I am using firebase identity toolkit from googleapi for phone verification on web. I have handled recaptcha for website too using site key and went to do post request, but I am not able to send sms to mobile as I am stucked for past 2 days on same problem sadly. here is following steps I did

  1. Enable phone authentication mechanism from firebase console.
  2. Enable web api key for same firebase project.
  3. Go to firebase recapcha admin and enable my host website to get repactha token.

Finally I did post request using api key from firebase console and captcha token from front end side and phone number in my server side. But the json response I am getting is this as below.

 {'error': {'code': 400, 
'message': 'CAPTCHA_CHECK_FAILED : Recaptcha verification failed - SITE_MISMATCH', 'errors': [{'message': 'CAPTCHA_CHECK_FAILED : Recaptcha verification failed - SITE_MISMATCH', 'domain': 
'global', 'reason': 'invalid'}]}}
Run Code Online (Sandbox Code Playgroud)

Here is some code I made my hand dirty.

def _factory(self):
    firebase_api_key = settings.FIREBASE_API_KEY

    params = (
        ('key', firebase_api_key),
    )

    json_data = {
        'phoneNumber': self._data['phone_number'],
        'recaptchaToken': self._data['recaptchaToken'],
    }

    secret_key = 'MY_SERVER_SIDE_RECAPTCHA_SITE_KEY'
    headers = {"Content-Type": "application/x-www-form-urlencoded"}
    data = {
        'secret': secret_key,
        'response': self._data['recaptchaToken']
    }

    url = 'https://www.google.com/recaptcha/api/siteverify'

    captacha_verify = requests.post(url, headers=headers, params=data)
    print(captacha_verify.json())
    headers = {
        'content-type': 'application/json',
    }

    new = requests.post('https://identitytoolkit.googleapis.com/v1/accounts:sendVerificationCode',params=params,json=json_data,headers = headers)

    print(new.json())
Run Code Online (Sandbox Code Playgroud)

Any help feedbaack will be very useful. I am not using firebase Database. I just want to minimize cost of sms to verify user via phone number.

Niz*_*zar 2

我相信您需要使用getRecaptchaParam()方法才能生成站点密钥。

结果将是json包含密钥的。如果我没记错的话,您可以将其传递到请求中。

{
  "recaptchaSiteKey": string
}
Run Code Online (Sandbox Code Playgroud)