Token - 10quality/license-keys-php-client GitHub Wiki
This endpoint is only available for the paid extension.
token()
requests the token endpoint and returns the response.
Call and parameters
$response = Api::token($client, $getClosure);
Parameters
Parameter | Type | Description |
---|---|---|
$client | Client |
An instance of the client. |
$getClosure | Closure (callable on php5) |
A function that should return an instance of LicenseRequest . Use LicenseRequest::token() to send a request for this endpoint. |
Returns
Type | Description |
---|---|
null |
If response is empty. |
object |
The decoded response as an object. Use isset($response->error) to check if response had an error. Use isset($response->access_token) to check if response is a token. |
Usage
The following example will show how to request a token.
$licenseKey = '1564d65f4s6165esample-1';
$token = Api::token(
Client::instance(), // Client instance
function() use($licenseKey) {
// Use LicenseRequest::token() for this endpoint
return LicenseRequest::token(
'https://your-domain.com/wp-admin/admin-ajax.php', // API's base url
$licenseKey
);
}
);
API Handlers
You can specify the API handler to use when creating the license request, is the 3rd parameter. If no handler is specified, WP Ajax configuration will be used as default.
$licenseKey = '1564d65f4s6165esample-1';
$token = Api::token(
Client::instance(), // Client instance
function() use($licenseKey) {
// Use LicenseRequest::token() for this endpoint
return LicenseRequest::token(
'https://your-domain.com', // API's base url
$licenseKey,
'wp_rest'
);
}
);
Using the token
The captured $token
must be used to set the authorization header for the activate
, validate
and deactivate
endpoints.
if (isset($token->access_token)) {
$response = Api::activate(
Client::instance()->header('Authorization', $token->token_type . ' ' . $token->access_token),
function() {
// Code here...
},
function($licenseString) {
// Code here...
}
);
}