class TokenGenerator in Auth0 Single Sign On 8.2
Class TokenGenerator. Generates HS256 ID tokens.
@package Auth0\SDK\API\Helpers
Hierarchy
- class \Auth0\SDK\API\Helpers\TokenGenerator
Expanded class hierarchy of TokenGenerator
Deprecated
5.6.0, not used and no replacement provided.
1 file declares its use of TokenGenerator
- TokenGeneratorTest.php in vendor/
auth0/ auth0-php/ tests/ API/ Helpers/ TokenGeneratorTest.php
File
- vendor/
auth0/ auth0-php/ src/ API/ Helpers/ TokenGenerator.php, line 14
Namespace
Auth0\SDK\API\HelpersView source
class TokenGenerator {
/**
* Default token expiration time.
*/
const DEFAULT_LIFETIME = 3600;
/**
* Audience for the ID token.
*
* @var string
*/
protected $audience;
/**
* Secret used to encode the token.
*
* @var string
*/
protected $secret;
/**
* TokenGenerator constructor.
*
* @param string $audience ID token audience to set.
* @param string $secret Token encryption secret to encode the token.
*/
public function __construct($audience, $secret) {
$this->audience = $audience;
$this->secret = $secret;
}
/**
* Create the ID token.
*
* @param array $scopes Array of scopes to include.
* @param integer $lifetime Lifetime of the token, in seconds.
* @param boolean $secret_encoded True to base64 decode the client secret.
*
* @return string
*/
public function generate(array $scopes, $lifetime = self::DEFAULT_LIFETIME, $secret_encoded = true) {
$time = time();
$payload = [
'iat' => $time,
'scopes' => $scopes,
'exp' => $time + $lifetime,
'aud' => $this->audience,
];
$payload['jti'] = md5(json_encode($payload));
$secret = $secret_encoded ? base64_decode(strtr($this->secret, '-_', '+/')) : $this->secret;
return JWT::encode($payload, $secret);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TokenGenerator:: |
protected | property | Audience for the ID token. | |
TokenGenerator:: |
protected | property | Secret used to encode the token. | |
TokenGenerator:: |
constant | Default token expiration time. | ||
TokenGenerator:: |
public | function | Create the ID token. | |
TokenGenerator:: |
public | function | TokenGenerator constructor. |