Download the PHP package descope/descope-php without Composer
On this page you can find all versions of the php package descope/descope-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download descope/descope-php
More information about descope/descope-php
Files in descope/descope-php
Package descope-php
Short Description Descope SDK for PHP
License MIT
Homepage https://github.com/descope/php-sdk
Informations about the package descope-php
by Descope
Overview
The Descope SDK for PHP provides convenient access to Descope authentication. You can read more on the Descope Website.
Getting started
Requirements
Installation
Install the package with Composer
:
You'll need to set up a .env
file in the root directory with your Descope Project ID, which you can get from the Console like this:
Using the SDK
In order to use the SDK you will need to initialize a DescopeSDK
object with your Descope Project ID you defined in your .env
file, like this:
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:
To use the Laravel cache in the SDK:
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:
Authentication Methods
Passwords
Sign Up
Sign In
Send Reset Password
Update Password
Replace Password
Get Password Policy
SSO
SSO Sign In
Exchange Token
Session Management
DescopeSDK->verify($sessionToken)
- will validate the session token and return either TRUE or FALSE, depending on if the JWT is valid and expired.DescopeSDK->refreshSession($refreshToken)
- will refresh your session and return a new session token, with the refresh token.DescopeSDK->verifyAndRefreshSession($sessionToken, $refreshToken)
- will validate the session token and return either TRUE or FALSE, and will refresh your session and return a new session token.DescopeSDK->logout($refreshToken)
- will invalidate the refresh token and log the user out of the current session.-
DescopeSDK->logoutAll($refreshToken)
- will invalidate all refresh tokens associated with a given project, thereby signing out of all sessions across multiple applications. DescopeSDK->getClaims($sessionToken)
- will return all of the claims from the JWT in an array format.DescopeSDK->getUserDetails($refreshToken)
- will return all of the user information (email, phone, verification status, etc.) using a provided refresh token.
User Management Functions
Each of these functions have code examples on how to use them.
Some of these values may be incorrect for your environment, they exist purely as an example for your own implementation.
Create User
Update User
Invite User
Batch Invite
Delete User
Search All Users
Add Tenant
Remove Tenant
Set Tenant Roles
Add Tenant Roles
Remove Tenant Roles
Set Temporary Password
Set Active Password
Set Password
Unit Testing
The PHP directory includes unit testing using PHPUnit. You can insert values for session token and refresh tokens in the src/tests/DescopeSDKTest.php
file, and run to validate whether or not the functions are operating properly.
To run the tests, run this command:
Running the PHP Sample App
In the sample/static/descope.js
, replace the projectId with your Descope Project ID, which you can find in the Descope Console.
If you haven't already, make sure you run the composer command listed above, to install the necessary SDK packages.
Then, run this command from the root directory, to start the sample app:
The app should now be accessible at http://localhost:3000/ from your web browser.
This sample app showcases a Descope Flow using the WebJS SDK and PHP sessions to retain user information across multiple pages. It also showcases initializing the SDK and using it to validate the session token from formData sent from login.php
.
Feedback
Contributing
We appreciate feedback and contribution to this repository!
Raise an issue
To provide feedback or report a bug, please raise an issue on our issue tracker.
This project is licensed under the MIT license. See the LICENSE file for more info.
All versions of descope-php with dependencies
guzzlehttp/guzzle Version 7.9.2 as 7.9.3
paragonie/constant_time_encoding Version ^2.7.0
vlucas/phpdotenv Version ^5.6.1