1. Go to this page and download the library: Download descope/descope-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
descope / descope-php example snippets
use Descope\SDK\DescopeSDK;
$descopeSDK = new DescopeSDK([
'projectId' => $_ENV['DESCOPE_PROJECT_ID'],
'managementKey' => $_ENV['DESCOPE_MANAGEMENT_KEY'] // Optional, only used for Management functions
]);
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);
}
}
use Descope\SDK\DescopeSDK;
use App\Cache\LaravelCache;
$descopeSDK = new DescopeSDK([
'projectId' => $_ENV['DESCOPE_PROJECT_ID'],
'managementKey' => $_ENV['DESCOPE_MANAGEMENT_KEY'],
], new LaravelCache());
$descopeSDK->management->user->setTemporaryPassword("testuser1", new UserPassword(cleartext: "temporaryPassword123"));
$descopeSDK->management->user->setActivePassword("testuser1", new UserPassword(cleartext: "activePassword123"));
$descopeSDK->management->user->setPassword("testuser1", new UserPassword(cleartext: "password123"), true);
use Descope\SDK\Management\Password\UserPassword;
// Create a password with cleartext
$password = new UserPassword(cleartext: "mysecretpassword");
// Use it in user creation
$response = $descopeSDK->management->user->create(
"user123", // loginId
"[email protected]", // email
"+1234567890", // phone
"John Doe", // displayName
"John", // givenName
null, // middleName
"Doe", // familyName
null, // picture
null, // customAttributes
true, // verifiedEmail
true, // verifiedPhone
null, // inviteUrl
null, // additionalLoginIds
null, // ssoAppIds
$password, // password
["user"], // roleNames
null // userTenants
);
use Descope\SDK\Management\Password\UserPassword;
use Descope\SDK\Management\Password\UserPasswordBcrypt;
// Create a bcrypt hashed password
$hashedPassword = new UserPasswordBcrypt('$2a$12$XlQwF3/7ohdzYrE0LC4A.O');
$password = new UserPassword(null, $hashedPassword);
// Use it in user creation
$response = $descopeSDK->management->user->create(
"user123", // loginId
"[email protected]", // email
null, // phone
"John Doe", // displayName
null, // givenName
null, // middleName
null, // familyName
null, // picture
null, // customAttributes
true, // verifiedEmail
false, // verifiedPhone
null, // inviteUrl
null, // additionalLoginIds
null, // ssoAppIds
$password, // password
["user"], // roleNames
null // userTenants
);
use Descope\SDK\Management\Password\UserPassword;
use Descope\SDK\Management\Password\UserPasswordSha;
// Create a SHA hashed password
$hashedPassword = new UserPasswordSha(
'5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', // hash
'sha256' // type
);
$password = new UserPassword(null, $hashedPassword);
// Use it in user creation or password replacement
...
use Descope\SDK\Management\Password\UserPassword;
use Descope\SDK\Management\Password\UserPasswordMD5;
// Create an MD5 hashed password
$hashedPassword = new UserPasswordMD5('87f77988ccb5aa917c93201ba314fcd4');
$password = new UserPassword(null, $hashedPassword);
// Use it in user creation or password replacement
...
use Descope\SDK\Management\Password\UserPassword;
use Descope\SDK\Management\Password\UserPasswordPbkdf2;
// Create a PBKDF2 hashed password
$hashedPassword = new UserPasswordPbkdf2(
'hashvalue', // hash
'saltvalue', // salt
10000, // iterations
'sha256' // variant (sha1, sha256, sha512)
);
$password = new UserPassword(null, $hashedPassword);
// Use it in user creation or password replacement
...
use Descope\SDK\Management\Password\UserPassword;
use Descope\SDK\Management\Password\UserPasswordDjango;
// Create a Django hashed password
$hashedPassword = new UserPasswordDjango('pbkdf2_sha256$30000$hashvalue');
$password = new UserPassword(null, $hashedPassword);
// Use it in user creation or password replacement
...
use Descope\SDK\Management\Password\UserPassword;
use Descope\SDK\Management\Password\UserPasswordFirebase;
// Create a Firebase hashed password
$hashedPassword = new UserPasswordFirebase(
'hashvalue', // hash
'saltvalue', // salt
'saltsep', // salt separator
'signerkey', // signer key
14, // memory cost
8 // rounds
);
$password = new UserPassword(null, $hashedPassword);
// Use it in user creation or password replacement
...