Skip to main content

OSCU API Authentication

All interactions with the KRA eTIMS OSCU API require authentication via OAuth 2.0 token. Use the tabs below to see examples in PHP, JavaScript/ TypeScript, and Python.


require_once __DIR__ . '/../vendor/autoload.php';

use KraEtimsSdk\Services\AuthOClient;

$config = [
'env' => 'sbx',
'auth' => [
'sbx' => [
'consumer_key' => getenv('KRA_CONSUMER_KEY'),
'consumer_secret' => getenv('KRA_CONSUMER_SECRET'),
],
'prod' => [
'consumer_key' => getenv('KRA_CONSUMER_KEY'),
'consumer_secret' => getenv('KRA_CONSUMER_SECRET'),
]
],
'oscu' => [
'tin' => getenv('KRA_TIN'),
'bhf_id' => getenv('KRA_BHF_ID') ?: '01',
'device_serial' => getenv('DEVICE_SERIAL'),
'cmc_key': getenv('CMC_KEY'),
]
];

$auth = new AuthOClient($config);

try {
$auth->forgetToken(); // Clear cached token
$token = $auth->token(true); // Force refresh
echo "✅ Token OK: " . substr($token, 0, 25) . "...\n";
} catch (\KraEtimsSdk\Exceptions\AuthenticationException $e) {
echo "❌ Auth failed: " . $e->getMessage();
}

Once you have the token, initialize the EtimsOClient to call API endpoints:

$etims = new EtimsOClient($config, $auth);

Next Steps