Skip to content

Commit

Permalink
Add code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso committed Feb 6, 2025
1 parent 5048792 commit 22cf023
Showing 1 changed file with 97 additions and 2 deletions.
99 changes: 97 additions & 2 deletions src/content/docs/en/basics/server-side-verification.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,105 @@ with the request. The closer the score is to 1, the more likely it is that the r
}
```
## Verification Code Examples
### JavaScript
<section id="js">
```javascript
const fetch = require('node-fetch');
async function verifyToken(token) {
const response = await fetch('https://api.prosopo.io/siteverify', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({secret: 'your_secret_key', token}),
});
return response.json().verified || false; // Return verified field, default to false
}
```
</section>
### PHP
<section id="php">
```php
<?php
function verifyToken($token) {
$url = 'https://api.prosopo.io/siteverify';
$data = json_encode(["secret" => "your_secret_key", "token" => $token]);
$options = [
'http' => [
'header' => "Content-Type: application/json\r\n",
'method' => 'POST',
'content' => $data,
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);
return $response["verified"] ?? false; // Return verified field, default to false
}
?>
```
</section>
### Python
<section id="python">
```python
import requests
def verify_token(token):
url = "https://api.prosopo.io/siteverify"
data = {"secret": "your_secret_key", "token": token}
response = requests.post(url, json=data)
return response.json().get("verified", False) # Return verified field, default to False
```
</section>
### Java
<section id="java">
```java
import java.io.*;
import java.net.*;
import org.json.JSONObject;
public class ProcaptchaVerification {
public static boolean verifyToken(String token) throws Exception {
URL url = new URL("https://api.prosopo.io/siteverify");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
String jsonInputString = "{\"secret\":\"your_secret_key\", \"token\":\"" + token + "\"}";
try (OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String responseLine;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
// Parse JSON response
JSONObject jsonResponse = new JSONObject(response.toString());
return jsonResponse.optBoolean("verified", false); // Default to false if not found
}
}
```
</section>
## Verification Package
We have a JavaScript implementation of the Procaptcha verification package and we are working on
delivering additional language support.
We have a JavaScript implementation of the Procaptcha verification package [available on npm](https://www.npmjs.com/package/@prosopo/server).
### JavaScript / TypeScript Verification
Expand Down

0 comments on commit 22cf023

Please sign in to comment.