Created
June 24, 2022 18:04
-
-
Save jeffehobbs/7ba64eab91a9eeae2bd0a89276094ddc to your computer and use it in GitHub Desktop.
recaptcha_v3_endpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# minimally viable recaptcha v3 lambda | |
# jeffehobbs@gmail.com | |
from flask import Flask, Response, request, jsonify | |
from flask_cors import CORS | |
import requests | |
SECRET_KEY = 'your_recaptcha_v3_server_side_token' | |
app = Flask(__name__) | |
CORS(app) | |
@app.route('/') | |
def index(): | |
response = jsonify(success=True) | |
return response | |
@app.route('/verify', methods=['GET', 'POST']) | |
def get_token(): | |
if request.method == 'POST': | |
token = request.form['g-recaptcha-response'] | |
else: | |
token = request.args.get('token') | |
response = verify_token(token) | |
return(jsonify(response)) | |
def verify_token(token): | |
api_url = 'https://www.google.com/recaptcha/api/siteverify' | |
data = {'secret': SECRET_KEY, 'response': token} | |
r = requests.post(api_url, data=data) | |
return(r.json()) | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=5000, debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment