PHP code example of keystackapp / keystack-php-auth
1. Go to this page and download the library: Download keystackapp/keystack-php-auth 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/ */
keystackapp / keystack-php-auth example snippets
use KeyStackApp\Encryptor\ApiKeyExtractor;
$apiKeyExtractor = new ApiKeyExtractor();
$payload = $apiKeyExtractor->getApiKeyPayload($apiKey);
use KeyStackApp\Encryptor\KeyEncryptor;
$keyEncryptor = new KeyEncryptor();
$encryptedApiKey = $keyEncryptor->getEncryptedApiKey($apiKey);
use KeyStackApp\Encryptor\CredentialExtractor;
$credentialExtractor = new CredentialExtractor();
$loginInputData = $credentialExtractor->getLoginInputData($apiKey);
use KeyStackApp\Adapter\SessionAdapter;
$adapter = new SessionAdapter();
$adapter->storeToken($jwt);
if ($adapter->hasToken()) {
$token = $adapter->getToken();
}
$adapter->incrementLoginAttempt();
use KeyStackApp\Adapter\FileAdapter;
$adapter = new FileAdapter(__DIR__ . '/var/keystack');
$adapter->storeToken($jwt);
$count = $adapter->incrementLoginAttempt();
use KeyStackApp\Adapter\RedisAdapter;
$redis = new \Redis();
$redis->connect('redis.internal', 6379);
$adapter = new RedisAdapter($redis, ttl: 1800);
$adapter->storeToken($jwt);
use KeyStackApp\Adapter\DatabaseAdapter;
$pdo = new \PDO('mysql:host=localhost;dbname=app', 'user', 'pass', [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
]);
$adapter = new DatabaseAdapter($pdo, keyIdentifier: 'user:123');
$adapter->storeToken($jwt);
$attempts = $adapter->getLoginAttemptCount();
use KeyStackApp\Adapter\WPTransientAdapter;
$adapter = new WPTransientAdapter(tokenTtl: 3600, loginAttemptTtl: 86400);
$adapter->storeToken($jwt);
use KeyStackApp\Adapter\TokenStorageAdapterInterface;
class MyCacheAdapter implements TokenStorageAdapterInterface {
public function storeToken(string $token): bool { /* ... */ }
public function getToken(): ?string { /* ... */ }
public function clearToken(): bool { /* ... */ }
public function hasToken(): bool { /* ... */ }
public function incrementLoginAttempt(): int { /* ... */ }
public function getLoginAttemptCount(): int { /* ... */ }
public function resetLoginAttemptCount(): bool { /* ... */ }
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.