Dog-Lee commented on a change in pull request #6512:
URL: https://github.com/apache/apisix/pull/6512#discussion_r826847315



##########
File path: apisix/plugins/recaptcha.lua
##########
@@ -0,0 +1,101 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--     http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+local core = require("apisix.core")
+local http = require("resty.http")
+
+local schema = {
+    type = "object",
+    properties = {
+        secret_key = { type = "string" },
+        parameter_source = { type = "string", default = "header", enum = { 
"header", "query" } },
+        parameter_name = { type = "string", default = "captcha" },
+        response = {
+            type = "object",
+            properties = {
+                content_type = { type = "string", default = "application/json; 
charset=utf-8" },
+                status_code = { type = "number", default = 400 },
+                body = { type = "string", default = '{"message": "invalid 
captcha"}' }
+            }
+        },
+    },
+    required = { "secret_key" },
+}
+
+local recaptcha_url = "https://www.recaptcha.net";
+
+local _M = {
+    version = 0.1,
+    priority = 700,
+    name = "recaptcha",
+    schema = schema,
+}
+
+function _M.check_schema(conf, schema_type)
+    return core.schema.check(schema, conf)
+end
+
+local function retrieve_captcha(ctx, conf)
+    local captcha
+    if conf.parameter_source == "header" then
+        captcha = core.request.header(ctx, conf.parameter_name)
+    elseif conf.parameter_source == "query" then
+        local uri_args = core.request.get_uri_args(ctx) or {}
+        captcha = uri_args[conf.parameter_name]
+    end
+    return captcha
+end
+
+function _M.access(conf, ctx)
+    local path = ctx.var.uri
+    local method = core.request.get_method()
+
+    core.log.debug("path: ", path, ", method: ", method, ", conf: ", 
core.json.encode(conf))
+
+    local invalid_captcha = true
+    local captcha = retrieve_captcha(ctx, conf)
+    if captcha ~= nil and captcha ~= "" then
+        local httpc = http.new()
+        local secret = conf.secret_key
+        local remote_ip = core.request.get_remote_client_ip(ctx)
+        local res, err = httpc:request_uri(recaptcha_url .. 
"/recaptcha/api/siteverify", {

Review comment:
       
https://developers.google.com/recaptcha/docs/faq?hl=en#can-i-use-recaptcha-globally
   > please use "www.recaptcha.net" in your code in circumstances when 
"www.google.com" is not accessible.
   
   Due to the GWF, the Chinese server might not be able to connect with 
`www.google.com` (it reproduces in my local env). I think this might be the 
reason why it has `www.recaptcha.net` domain.
   
   @nic-6443 I would say it's not a must-have feature in the current stage, and 
I can add it in the next version. Can we? : )




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to