Namespace: Antavo\
SignedToken
Example:
Creating a new token
$token = new Antavo\SignedToken\SignedToken($token_secret);
$token->setPayload(array('some_key' => 'some_value'));
echo $token->getToken();
Example:
Extracting payload from a token string
try {
$token = new Antavo\SignedToken\SignedToken($token_secret);
$token->setToken($input_token);
var_dump($token->getPayload());
} catch (Antavo\SignedToken\Exceptions\Exception $e) {
echo $e->getMessage();
}
Located at signed-token/src/SignedToken.php
Methods summary
public
|
#
__construct( string $secret = NULL, integer $expires_at = NULL )
Constructs token object: sets secret string and expiration time.
Constructs token object: sets secret string and expiration time.
Parameters
|
public
string
|
#
__toString( )
Shorthand method for getting token string.
Shorthand method for getting token string.
Returns
string
See
|
public
string
|
#
getAlgorithm( )
Returns algorithm used for creating the token digest.
Returns algorithm used for creating the token digest.
Returns
string
|
public
integer
|
#
getCalculatedExpirationTime( )
Returns calculated expiration time.
Returns calculated expiration time.
Returns
integer If set value is a time-to-live value — meaning it's
smaller than or equals to 30 days (in seconds) — it is offsetted
with current time.
|
public
integer
|
#
getExpirationTime( )
Returns token expiration time as Unix Timestamp.
Returns token expiration time as Unix Timestamp.
Returns
integer
|
public
array
|
#
getPayload( )
Returns payload data extracted from token string.
Returns payload data extracted from token string.
Returns
array
|
public
string
|
#
getSecret( )
Returns secret string used to create the token digest.
Returns secret string used to create the token digest.
Returns
string
|
final public
string
|
#
getToken( )
Returns token string. If a setter call occurred since last calculation,
it regenerates the string.
Returns token string. If a setter call occurred since last calculation,
it regenerates the string.
Returns
string
|
public
boolean
|
#
isExpired( )
Tells if token expiration time had passed already.
Tells if token expiration time had passed already.
Returns
boolean
|
public
string
|
#
saltDigest( string $digest )
By overriding this method you can provide a custom mechanism to
manipulate token digest before use.
By overriding this method you can provide a custom mechanism to
manipulate token digest before use.
Parameters
- $digest
- Digest calculated from payload.
Returns
string Salted digest that will be used for token.
|
public
Antavo\SignedToken\SignedToken
|
#
setAlgorithm( string $algorithm )
Sets algorithm used for creating the token digest.
Sets algorithm used for creating the token digest.
Parameters
Returns
Link
|
public
Antavo\SignedToken\SignedToken
|
#
setExpirationTime( integer $expires_at )
Sets expiration time for the token.
Sets expiration time for the token.
Parameters
- $expires_at
Unix Timestamp of expiration time. If given
value is smaller than or equals to 30 days (in seconds) then it is
handled as a relative time-to-live value. 0 means it will never expire.
Float values are casted to integer, while non-numeric values are
discarded.
Returns
|
public
Antavo\SignedToken\SignedToken
|
#
setPayload( array $payload )
Sets payload data to embed into the token string.
Sets payload data to embed into the token string.
Parameters
Returns
|
public
Antavo\SignedToken\SignedToken
|
#
setSecret( string $secret )
Sets string to use for token digest calculation.
Sets string to use for token digest calculation.
Parameters
- $secret
- Non-scalar values are discarded.
Returns
|
final public
Antavo\SignedToken\SignedToken
|
#
setToken( string $token )
Restores an object state from token string.
Restores an object state from token string.
Parameters
- $token
Token string to process. Non-string values are
discarded.
Returns
Throws
|