Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gaokevin1 committed Jan 7, 2025
2 parents 187f446 + eb3f69b commit 496e6c2
Show file tree
Hide file tree
Showing 29 changed files with 903 additions and 2,530 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: PHP Unit Tests

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

env:
DESCOPE_PROJECT_ID: ${{ vars.DESCOPE_PROJECT_ID }}

strategy:
matrix:
php-version: [8.1, 7.4]

steps:
- uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Install dependencies
run: composer install

- name: Run tests
run: vendor/bin/phpunit --configuration phpunit.xml
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,61 @@ $descopeSDK = new DescopeSDK([
]);
```

This SDK will easily allow you to handle Descope JWT tokens with the following built-in functions:
### Caching Mechanism

The Descope PHP SDK uses a caching mechanism to store frequently accessed data, such as JSON Web Key Sets (JWKs) for session token validation. By default, the SDK uses **APCu** for caching, provided it is enabled and configured in your environment. If APCu is not available, and no other caching mechanism is provided, caching is disabled.

By using the `CacheInterface`, you can integrate the Descope PHP SDK with any caching mechanism that suits your application, ensuring optimal performance in both small and large-scale deployments.

#### Custom Caching with `CacheInterface`

The SDK allows you to provide a custom caching mechanism by implementing the `CacheInterface`. This interface defines three methods that any cache implementation should support:

- `get(string $key)`: Retrieve a value by key.
- `set(string $key, $value, int $ttl = 3600): bool`: Store a value with a specified time-to-live (TTL).
- `delete(string $key): bool`: Remove a value by key.

You can provide your custom caching implementation by creating a class that implements `CacheInterface`. Here’s an example using Laravel’s cache system:

```php
namespace App\Cache;

use Descope\SDK\Cache\CacheInterface;
use Illuminate\Support\Facades\Cache;

class LaravelCache implements CacheInterface
{
public function get(string $key)
{
return Cache::get($key);
}

public function set(string $key, $value, int $ttl = 3600): bool
{
// Laravel TTL is in minutes
return Cache::put($key, $value, max(1, ceil($ttl / 60)));
}

public function delete(string $key): bool
{
return Cache::forget($key);
}
}
```

To use the Laravel cache in the SDK:

```php
use Descope\SDK\DescopeSDK;
use App\Cache\LaravelCache;

$descopeSDK = new DescopeSDK([
'projectId' => $_ENV['DESCOPE_PROJECT_ID'],
'managementKey' => $_ENV['DESCOPE_MANAGEMENT_KEY'],
], new LaravelCache());
```

Once you've configured your caching, you're ready to use the SDK. This SDK will easily allow you integrate Descope functionality with the following built-in functions:

## Password Authentication

Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
],
"require": {
"php": "^7.3 || ^8.0",
"web-token/jwt-framework": "2.2.11 as 2.3.0",
"guzzlehttp/guzzle": "7.9.2 as 7.9.3",
"paragonie/constant_time_encoding": "^2.7.0",
"vlucas/phpdotenv": "^5.6.1"
Expand Down
Loading

0 comments on commit 496e6c2

Please sign in to comment.