-
Notifications
You must be signed in to change notification settings - Fork 5
Token
Ale Mostajo edited this page Sep 30, 2020
·
1 revision
This endpoint is only available for the paid extension.
token()
requests the token endpoint and returns the response.
$response = Api::token($client, $getClosure);
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. |
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. |
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
);
}
);
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'
);
}
);
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...
}
);
}