Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This documentation provides an overview of how to configure and authorize requests to the Aspose Barcode Cloud API using JWT and external authorization methods. It covers key code examples and settings needed to enable secure and authorized API requests.
Note: For manage authorization you should have a Client Id and Client Secret. How to get it described in Quick Start Section
Aspose Barcode Cloud API supports two main authorization methods:
When using JWT, the API classes automatically obtains a token and includes it in each API request.
To set up JWT authorization, specify the clientId
and clientSecret
:
$config = new Configuration();
$config->setClientId('ClientId from https://dashboard.aspose.cloud/applications');
$config->setClientSecret('Client Secret from https://dashboard.aspose.cloud/applications');
$api = new GenerateApi(null, $config);
Upon setup, the internal SDK methods handles token generation and token refresh:
clientId
and clientSecret
.External authorization allows you to manually manage tokens. Assign your JWT token directly to accessToken
and leave clientId
and clientSecret
blank.
Example configuration with External Authorization:
$config = new Configuration();
$config->setAccessToken("<Your-External-Jwt-Token>")
$api = new RecognizeApi(null, $config);
In this mode, the API sends the provided JWT in the Authorization header without attempting to generate or refresh the token.
To fetch a new token, send a POST request to https://id.aspose.cloud/connect/token with the application/x-www-form-urlencoded
content type. In the request body, specify the following parameters:
grant_type=client_credentials
client_id=<Your-Client-Id>
client_secret=<Your-Client-Secret>
A Code example for fetching token:
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$clientId = 'Client Id from https://dashboard.aspose.cloud/applications';
$clientSecret = 'Client Secret from https://dashboard.aspose.cloud/applications';
// Check the client_id is changed to not break GitHub CI pipeline
if (str_starts_with($clientId, "Client Id")) {
echo "clientId not configured. Skip this snippet test";
return;
}
$url = 'https://id.aspose.cloud/connect/token';
$data = [
'grant_type' => 'client_credentials',
'client_id' => $clientId,
'client_secret' => $clientSecret
];
$client = new Client();
$response = $client->post($url, [
'form_params' => $data,
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded'
]
]);
$body = $response->getBody()->getContents();
$statusCode = $response->getStatusCode();
if ($statusCode >= 200 && $statusCode < 300) {
$bodyArray=json_decode($body, true);
$token=$bodyArray["access_token"];
echo "Token recieved successfully\n";
// To veiw token uncomment next line
// echo "$token";
} else {
throw new Exception("Unexpected HTTP code: $statusCode\nResponse: $body\n");
}
Configuring authorization in the Aspose.BarCode.Cloud SDK for PHP allows secure, authenticated access to barcode-related functionalities. Choose JWT authorization wiht client id and secret for automatic token management or external for custom token handling.
With these examples and explanations, you should be able to set up authorization for the Aspose.BarCode.Cloud SDK for PHP.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.