DocsOther systemsSigned user token

Signed user token

For your developer. Your server proves who is signed in; the browser never sees the secret.

  1. Add a page on your own server, for example GET /codexta/token, on the same address as your application.

  2. Look up the signed-in user from your own session. For nobody, answer {} and the user chats as a guest.

  3. Sign an HS256 token with your signing secret and answer {"token": "…"}. Send Cache-Control: no-store.

    ClaimValue
    tenantYour account name. Required.
    expExpiry, at most 5 minutes ahead. Use 2 minutes. Required.
    subYour own user id. Present means signed in.
    email, nameOptional, shown to your team.
    jtiOptional random id so a token works once.
  4. Open your application signed in and out, and check the chat treats each correctly.

Node example

// npm i express jsonwebtoken
const express = require('express');
const jwt = require('jsonwebtoken');
const crypto = require('crypto');
const SECRET = process.env.CODEXTA_SIGNING_SECRET; // server side only
const app = express();

app.get('/codexta/token', (req, res) => {
  res.set('Cache-Control', 'no-store');
  const user = req.session && req.session.user; // your own session
  if (!user) return res.json({});
  res.json({ token: jwt.sign(
    { tenant: 'your-account-name', sub: String(user.id),
      email: user.email, name: user.name, jti: crypto.randomUUID() },
    SECRET, { algorithm: 'HS256', expiresIn: 120 }) });
});

Tip. Keep the secret on the server only. A token can only identify a customer or a guest, never grant staff rights. To change the secret, ask us; the old one stops working at once.

← Connect a custom applicationAll docs

Was something unclear? Contact support