Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APPWRITE_ENDPOINT=
APPWRITE_PROJECT_ID=
APPWRITE_API_KEY=
6 changes: 6 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ jobs:

- run: git checkout HEAD^2

- name: Generate .env file
run: |
echo "APPWRITE_ENDPOINT=${{ secrets.APPWRITE_ENDPOINT }}" > .env
echo "APPWRITE_PROJECT_ID=${{ secrets.APPWRITE_PROJECT_ID }}" >> .env
echo "APPWRITE_API_KEY=${{ secrets.APPWRITE_API_KEY }}" >> .env

- name: Build
run: |
export PHP_VERSION=${{ matrix.php-versions }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/.idea/
/.idea/
.env
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ composer require utopia-php/abuse
The time limit abuse allow each key (action) to be performed [X] times in given time frame.
This adapter uses a MySQL / MariaDB to store usage attempts. Before using it create the table schema as documented in this repository (./data/schema.sql)

### Database adapter

```php
<?php

Expand Down Expand Up @@ -66,6 +68,38 @@ if($abuse->check()) {
}
```

### Appwrite TablesDB adapter

```php
<?php

require_once __DIR__ . '/../../vendor/autoload.php';

use Utopia\Abuse\Abuse;
use Utopia\Abuse\Adapters\TimeLimit\Appwrite\TablesDB as TablesDBAdapter;
use Appwrite\Client;

$client = (new Client())
->setEndpoint('[YOUR_ENDPOINT]')
->setProject('[YOUR_PROJECT_ID]')
->setKey('[YOUR_API_KEY]');
$databaseId = 'abuse';

// Limit login attempts to 10 time in 5 minutes time frame
$adapter = new TablesDBAdapter('login-attempt-from-{{ip}}', 10, (60 * 5), $client, $databaseId);

$adapter->setup(); //setup database as required
$adapter->setParam('{{ip}}', '127.0.0.1');

$abuse = new Abuse($adapter);

// Use vars to resolve adapter key

if($abuse->check()) {
throw new Exception('Service was abused!'); // throw error and return X-Rate limit headers here
}
```

**ReCaptcha Abuse**

The ReCaptcha abuse controller is using Google ReCaptcha service to detect when service is being abused by bots.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"ext-pdo": "*",
"ext-curl": "*",
"ext-redis": "*",
"utopia-php/database": "*"
"utopia-php/database": "3.*.*",
"appwrite/appwrite": "18.*.*"
},
"require-dev": {
"phpunit/phpunit": "9.*",
Expand Down
Loading