POST
/
api
/
v1
/
auth
/
socket-ticket
Socket handshake ticket
curl --request POST \
  --url https://api.example.com/api/v1/auth/socket-ticket
import requests

url = "https://api.example.com/api/v1/auth/socket-ticket"

response = requests.post(url)

print(response.text)
const options = {method: 'POST'};

fetch('https://api.example.com/api/v1/auth/socket-ticket', 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://api.example.com/api/v1/auth/socket-ticket",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "https://api.example.com/api/v1/auth/socket-ticket"

req, _ := http.NewRequest("POST", url, nil)

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.example.com/api/v1/auth/socket-ticket")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.example.com/api/v1/auth/socket-ticket")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body

Overview

Mints a short-lived, one-shot ticket the client uses to authenticate the WebSocket handshake. The pattern exists because Socket.IO does not carry an Authorization header reliably and passing a JWT in the query string leaks it into access logs. Flow:
  1. The authenticated client calls this endpoint over REST and receives { ticket: "..." }.
  2. The client connects to the WebSocket with ?ticket=<ticket> in the handshake URL.
  3. The realtime server atomically GETDELs the ticket from Redis — exactly one admission per ticket.
The ticket is a 256-bit base64url-encoded random string. It expires after 60 seconds and can be redeemed at most once.

Authentication

Bearer <accessToken> required. Scope: user.

Path parameters

None.

Query parameters

None.

Request body

None.

Response — 200 OK

FieldTypeNotesExample
ticketstringOne-shot Redis ticket. Pass as ?ticket=<value> on the WebSocket handshake URL. 60-second TTL.tk_eJp8nWv2sR4uT6xV9yY0bN3mK5jL6hG7fD3eA0c-aR4

Example response

{
  "ticket": "tk_eJp8nWv2sR4uT6xV9yY0bN3mK5jL6hG7fD3eA0c-aR4"
}

Error responses

StatusCodeMeaning
401UNAUTHENTICATEDMissing, malformed, or expired access token.
503SERVICE_UNAVAILABLERedis is not configured in this environment (dev-only).

Example error — 503

{
  "type": "https://api.swappr.co.uk/errors/service-unavailable",
  "title": "Service unavailable",
  "status": 503,
  "code": "SERVICE_UNAVAILABLE",
  "detail": "Redis not configured",
  "instance": "/api/v1/auth/socket-ticket",
  "requestId": "01HZQ7K3M4N5P6Q7R8S9T0V1W2"
}

Side effects

  • Writes a key socket:ticket:<ticket> to Redis with the user id as the value and a 60-second TTL.
  • The key is deleted atomically by the realtime server when the socket connects (GETDEL). After 60 seconds Redis evicts it automatically.

See also

  • Authentication — full token lifecycle, including socket handshake.
  • Login — issues the access token used here.

curl

curl -X POST https://api.swappr.co.uk/api/v1/auth/socket-ticket \
  -H "Authorization: Bearer $ACCESS_TOKEN"