Single sign-on: one-time login link to the control panel
Your client area or billing system can give customers a "Log in to Control Panel" button: it asks the API for a one-time link and sends the customer's browser to it.
Before you start
- An administrator or reseller API token that is not read only. Resellers need the Log in to customers' control panels privilege.
- The account must be active. A suspended account answers
422This account is suspended.
Request
curl -s -X POST -H "Authorization: Bearer $TOKEN" \
https://server1.example.com:2087/api/v1/accounts/shop1/login
Response:
{"status": 1, "data": {"url": "https://server1.example.com:2083/sso/4f1c…"}}
Use the link
- Request the link when the customer clicks the button, not in advance.
- Redirect the customer's browser to
data.urlat once. - The customer sees You are about to sign in to the hosting account shop1 (shop-example.com). and clicks Continue. They are signed in to the control panel.
Rules
- The link works once and within 60 seconds. After that the customer sees This sign-in link has expired or was already used. Open it again from your client area.
- The Continue step makes sure a link sent by someone else cannot silently sign a visitor in.
- Each link is recorded in Activity Log.
- The
/json-api/create_user_sessionfunction makes the same link for billing systems that use it.
Example in PHP
$ch = curl_init('https://server1.example.com:2087/api/v1/accounts/' . rawurlencode($username) . '/login');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $token],
]);
$answer = json_decode(curl_exec($ch), true);
if (!empty($answer['status'])) {
header('Location: ' . $answer['data']['url']);
exit;
}
echo $answer['error'] ?? 'Could not sign in.';
Common questions
Why does the link say it has expired although I just made it?
More than 60 seconds passed before the customer clicked Continue, or Continue was already clicked once with that link. Opening the link alone does not use it up. Create a new link on each click.
Thank you — this helps us improve the article.
Still stuck?
Ask the AI about your exact situation — it answers from this knowledge base — or contact us.
Related articles
- Suspend, change package, password or terminate via the API
Manage hosting accounts with the REST API: list, suspend, unsuspend, change password or package, terminate, list packages, task and server status.
- How to connect WHMCS to the control panel (provisioning module)
Install the WHMCS module, add the server with an API token and pick packages, so WHMCS creates, suspends, upgrades and terminates accounts.
- How to log in to a customer's control panel without the password
Open a hosting customer's control panel as them from the admin panel, to check a problem or make a change, then return to the admin panel with one click.