get hcaptcha sitekey using graphql

This commit is contained in:
Jonas Leder 2022-03-08 09:54:38 +01:00
parent 0349c0533e
commit 3eb89d763c
No known key found for this signature in database
GPG Key ID: 8A53DD45A7D7B44B
6 changed files with 125 additions and 16 deletions

View File

@ -1,7 +1,8 @@
{
"require": {
"aws/aws-sdk-php": "^3.181",
"guzzlehttp/guzzle": "^7.0"
"guzzlehttp/guzzle": "^7.0",
"webonyx/graphql-php": "^14.11"
},
"config": {
"vendor-dir": "public/API/vendor"

70
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f47a9b8d286ca72493a7fe02f263976e",
"content-hash": "31a3a0321659f9c8afff63a68a9fafb6",
"packages": [
{
"name": "aws/aws-crt-php",
@ -669,6 +669,72 @@
}
],
"time": "2021-05-27T12:26:48+00:00"
},
{
"name": "webonyx/graphql-php",
"version": "v14.11.5",
"source": {
"type": "git",
"url": "https://github.com/webonyx/graphql-php.git",
"reference": "ffa431c0821821839370a68dab3c2597c06bf7f0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/ffa431c0821821839370a68dab3c2597c06bf7f0",
"reference": "ffa431c0821821839370a68dab3c2597c06bf7f0",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": "^7.1 || ^8"
},
"require-dev": {
"amphp/amp": "^2.3",
"doctrine/coding-standard": "^6.0",
"nyholm/psr7": "^1.2",
"phpbench/phpbench": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.82",
"phpstan/phpstan-phpunit": "0.12.18",
"phpstan/phpstan-strict-rules": "0.12.9",
"phpunit/phpunit": "^7.2 || ^8.5",
"psr/http-message": "^1.0",
"react/promise": "2.*",
"simpod/php-coveralls-mirror": "^3.0",
"squizlabs/php_codesniffer": "3.5.4"
},
"suggest": {
"psr/http-message": "To use standard GraphQL server",
"react/promise": "To leverage async resolving on React PHP platform"
},
"type": "library",
"autoload": {
"psr-4": {
"GraphQL\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A PHP port of GraphQL reference implementation",
"homepage": "https://github.com/webonyx/graphql-php",
"keywords": [
"api",
"graphql"
],
"support": {
"issues": "https://github.com/webonyx/graphql-php/issues",
"source": "https://github.com/webonyx/graphql-php/tree/v14.11.5"
},
"funding": [
{
"url": "https://opencollective.com/webonyx-graphql-php",
"type": "open_collective"
}
],
"time": "2022-01-24T11:13:31+00:00"
}
],
"packages-dev": [],
@ -679,5 +745,5 @@
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.1.0"
"plugin-api-version": "2.0.0"
}

View File

@ -6,7 +6,15 @@ class contactMailButton extends HTMLElement {
}
async addButton() {
let sitekey = await (await fetch("/API/config.php?name=sitekey")).text();
var graphql = JSON.stringify({
query: "query {\r\n sitekey\r\n}"
})
var requestOptions = {
method: 'POST',
body: graphql,
};
let sitekey = (await (await fetch("/API/graphql.php", requestOptions)).json()).data.sitekey;
console.log(sitekey);
this.innerHTML = `E-Mail: <button id="emailButton" class="h-captcha" data-sitekey="${sitekey}" data-callback="onSubmit">laden</button><br>`;
const script = document.createElement("script");

View File

@ -1,12 +0,0 @@
<?php
require "./lib/config.php";
$configValue = $_GET['name'];
switch ($configValue){
case "sitekey":
echo($sitekey);
break;
default:
echo("notFound");
}

33
public/API/graphql.php Normal file
View File

@ -0,0 +1,33 @@
<?php
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
require 'vendor/autoload.php';
require "./lib/config.php";
require "./lib/mysql.php";
require "./queries/queries.php";
$schema = new Schema([
'query' => $queryType
]);
$rawInput = file_get_contents('php://input');
$input = json_decode($rawInput, true);
$query = $input['query'];
$variableValues = isset($input['variables']) ? $input['variables'] : null;
try {
$rootValue = [];
$result = GraphQL::executeQuery($schema, $query, $rootValue, null, $variableValues);
$output = $result->toArray();
} catch (\Exception $e) {
$output = [
'errors' => [
[
'message' => $e->getMessage()
]
]
];
}
header('Content-Type: application/json');
echo json_encode($output);

View File

@ -0,0 +1,13 @@
<?php
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
$queryType = new ObjectType([
'name' => 'Query',
'fields' => [
'sitekey' => [
'type' => Type::string(),
'resolve' => fn ($rootValue, $args) => $sitekey,
],
],
]);