curl --request POST \
--url https://your-instance.example.com/api/auth/exit-impersonation \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"originalAdminToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...",
"originalAdminUser": {
"id": "5f7b1c2e8a1d4e0012c3b4a5",
"email": "admin@acme.example",
"fullName": "Acme Admin",
"organizationId": "5f7b1c2e8a1d4e0012c3b4a5",
"accessRole": "ADMIN"
}
}
'import requests
url = "https://your-instance.example.com/api/auth/exit-impersonation"
payload = {
"originalAdminToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...",
"originalAdminUser": {
"id": "5f7b1c2e8a1d4e0012c3b4a5",
"email": "admin@acme.example",
"fullName": "Acme Admin",
"organizationId": "5f7b1c2e8a1d4e0012c3b4a5",
"accessRole": "ADMIN"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
originalAdminToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...',
originalAdminUser: {
id: '5f7b1c2e8a1d4e0012c3b4a5',
email: 'admin@acme.example',
fullName: 'Acme Admin',
organizationId: '5f7b1c2e8a1d4e0012c3b4a5',
accessRole: 'ADMIN'
}
})
};
fetch('https://your-instance.example.com/api/auth/exit-impersonation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/api/auth/exit-impersonation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'originalAdminToken' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...',
'originalAdminUser' => [
'id' => '5f7b1c2e8a1d4e0012c3b4a5',
'email' => 'admin@acme.example',
'fullName' => 'Acme Admin',
'organizationId' => '5f7b1c2e8a1d4e0012c3b4a5',
'accessRole' => 'ADMIN'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/api/auth/exit-impersonation"
payload := strings.NewReader("{\n \"originalAdminToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...\",\n \"originalAdminUser\": {\n \"id\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"email\": \"admin@acme.example\",\n \"fullName\": \"Acme Admin\",\n \"organizationId\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"accessRole\": \"ADMIN\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-instance.example.com/api/auth/exit-impersonation")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"originalAdminToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...\",\n \"originalAdminUser\": {\n \"id\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"email\": \"admin@acme.example\",\n \"fullName\": \"Acme Admin\",\n \"organizationId\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"accessRole\": \"ADMIN\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-instance.example.com/api/auth/exit-impersonation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"originalAdminToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...\",\n \"originalAdminUser\": {\n \"id\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"email\": \"admin@acme.example\",\n \"fullName\": \"Acme Admin\",\n \"organizationId\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"accessRole\": \"ADMIN\"\n }\n}"
response = http.request(request)
puts response.read_body{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "5f7b1c2e8a1d4e0012c3b4a5",
"email": "admin@acme.example",
"organizationId": "64a1b2c3d4e5f60012345678",
"accessRole": "ADMIN"
},
"message": "Impersonation exited successfully"
}{
"error": "Invalid or expired token",
"code": "TOKEN_EXPIRED"
}{
"error": "Invalid or expired token",
"code": "TOKEN_EXPIRED"
}Exit impersonation and restore original admin session
Verify the supplied original-admin token (captured at impersonation start) and return it so the client can restore the admin session. Only callable from a session whose token carries the isImpersonation flag.
curl --request POST \
--url https://your-instance.example.com/api/auth/exit-impersonation \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"originalAdminToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...",
"originalAdminUser": {
"id": "5f7b1c2e8a1d4e0012c3b4a5",
"email": "admin@acme.example",
"fullName": "Acme Admin",
"organizationId": "5f7b1c2e8a1d4e0012c3b4a5",
"accessRole": "ADMIN"
}
}
'import requests
url = "https://your-instance.example.com/api/auth/exit-impersonation"
payload = {
"originalAdminToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...",
"originalAdminUser": {
"id": "5f7b1c2e8a1d4e0012c3b4a5",
"email": "admin@acme.example",
"fullName": "Acme Admin",
"organizationId": "5f7b1c2e8a1d4e0012c3b4a5",
"accessRole": "ADMIN"
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
originalAdminToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...',
originalAdminUser: {
id: '5f7b1c2e8a1d4e0012c3b4a5',
email: 'admin@acme.example',
fullName: 'Acme Admin',
organizationId: '5f7b1c2e8a1d4e0012c3b4a5',
accessRole: 'ADMIN'
}
})
};
fetch('https://your-instance.example.com/api/auth/exit-impersonation', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/api/auth/exit-impersonation",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'originalAdminToken' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...',
'originalAdminUser' => [
'id' => '5f7b1c2e8a1d4e0012c3b4a5',
'email' => 'admin@acme.example',
'fullName' => 'Acme Admin',
'organizationId' => '5f7b1c2e8a1d4e0012c3b4a5',
'accessRole' => 'ADMIN'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/api/auth/exit-impersonation"
payload := strings.NewReader("{\n \"originalAdminToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...\",\n \"originalAdminUser\": {\n \"id\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"email\": \"admin@acme.example\",\n \"fullName\": \"Acme Admin\",\n \"organizationId\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"accessRole\": \"ADMIN\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-instance.example.com/api/auth/exit-impersonation")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"originalAdminToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...\",\n \"originalAdminUser\": {\n \"id\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"email\": \"admin@acme.example\",\n \"fullName\": \"Acme Admin\",\n \"organizationId\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"accessRole\": \"ADMIN\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-instance.example.com/api/auth/exit-impersonation")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"originalAdminToken\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1Zjdi...\",\n \"originalAdminUser\": {\n \"id\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"email\": \"admin@acme.example\",\n \"fullName\": \"Acme Admin\",\n \"organizationId\": \"5f7b1c2e8a1d4e0012c3b4a5\",\n \"accessRole\": \"ADMIN\"\n }\n}"
response = http.request(request)
puts response.read_body{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "5f7b1c2e8a1d4e0012c3b4a5",
"email": "admin@acme.example",
"organizationId": "64a1b2c3d4e5f60012345678",
"accessRole": "ADMIN"
},
"message": "Impersonation exited successfully"
}{
"error": "Invalid or expired token",
"code": "TOKEN_EXPIRED"
}{
"error": "Invalid or expired token",
"code": "TOKEN_EXPIRED"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Original admin JWT captured at impersonation start; re-verified server-side and must resolve to a SUPERADMIN/ADMIN role matching originalAdminUser.
Original admin payload (id, email, …) captured at impersonation start. Its id/email must match the verified originalAdminToken payload — guards against tampering.
Response
Impersonation exited
Returned by /api/auth/exit-impersonation after the original admin session is restored.
Original-admin access token to swap back into.
Compact User payload returned with auth tokens.
Show child attributes
Show child attributes
{
"id": "5f7b1c2e8a1d4e0012c3b4a5",
"email": "admin@acme.example",
"fullName": "Acme Admin",
"organizationId": "64a1b2c3d4e5f60012345678",
"accessRole": "ADMIN",
"conversationOpenPreference": "split"
}