Integrations

Connect your application with SSO

Sign your portal’s users in from your backend, with PHP and Node.js examples.

Download the Markdown

Updated on

pealHQ SSO signs the users of your application in to your feedback portal. Your server authenticates the user, signs a JWT with your workspace secret and redirects their browser to pealHQ. The portal account is created or updated at sign-in.

You can share this guide with your technical team or a coding agent. The values in the examples are fictitious. The real secret stays in your settings and in your server’s environment variables.

Before you start

  • You must administer a workspace whose plan includes the custom SSO feature. Its availability is shown in the settings.
  • Your application must already authenticate its users on the server side.
  • This mechanism uses a JWT signed with HS256 using a secret specific to the workspace. It is not a SAML or OpenID Connect connector.
  • SSO gives access to the customer portal and authenticates team members who are already authorised for this workspace. It does not create any administrators and does not change any roles. Invite your colleagues from pealHQ team management.

If the email address of the account signed in through SSO matches a single member already in this workspace’s team, the Admin button opens their admin area directly. The portal and the admin area share the same session: no additional Peal password or two-factor authentication code is requested. Your application handles authentication, including any second factor. The member’s comments appear as team replies; their customer profile keeps their votes, suggestions and subscriptions.

This access is limited to this workspace. It does not sign the member in to their central Peal account, to other workspaces or to the platform admin. An invitation that has not been accepted is not enough. Removing a member revokes their team access immediately. Signing out closes the portal and the admin area for this workspace; it does not close a separate central Peal session. Once the session expires, a new SSO sign-in is required to regain team rights, even if the portal remembers the customer profile.

Configure the workspace

  1. Open Settings → Customer sign-in in the pealHQ admin.
  2. Select SSO (your backend manages identity).
  3. Enter the Sign-in URL from your product, then save. This is the authenticated page of your application that will generate a fresh token and redirect the customer to the pealHQ callback. When a customer opens the portal directly without a session, the “Sign in from {workspace name}” button sends them to this URL.
  4. Copy the Callback URL, the Audience (workspace slug) and the Shared secret shown.
  5. Store these values in your application’s server configuration. Use a separate secret for each workspace and environment.

Example configuration in your application:

PEAL_SSO_CALLBACK_URL=https://acme.pealhq.com/sso/callback
PEAL_SSO_AUDIENCE=acme
PEAL_SSO_SECRET=remplacer-par-le-secret-affiche-dans-pealhq

These variable names are a convention for the examples, not variables to add to the pealHQ server. Use the secret exactly as shown, without Base64 decoding.

Depending on the environment, the callback may also look like https://preview.example/w/acme/sso/callback. Always copy the URL from the settings, rather than rebuilding it from the domain. The audience remains acme in both cases.

Sign-in flow

  1. The user clicks “Give feedback” in your application.
  2. Your backend checks their session and their authorisation to access the workspace concerned.
  3. Your backend takes the identifier, name and email from the authenticated account, then generates a new JWT valid for 60 seconds.
  4. It responds to the browser with an HTTP redirect to URL_DE_CALLBACK?token=JWT_ENCODE.
  5. pealHQ verifies the token, opens the workspace session with the existing member’s rights, where applicable, and redirects to the chosen destination in the same workspace, or to the list of requests by default.

The redirect must be followed by the user’s browser, so that it receives the session cookies. An HTTP call made only by your server does not sign their browser in. Open the portal as a top-level page.

To choose the landing page, add the optional redirect query parameter to the callback URL, alongside token:

https://acme.pealhq.com/sso/callback?token=JWT_ENCODE&redirect=/changelog
https://acme.pealhq.com/sso/callback?token=JWT_ENCODE&redirect=/roadmap
Value of redirectLanding page after sign-in
/changelogThe workspace’s updates.
/roadmapThe workspace’s roadmap.
/requests, parameter missing or any other valueThe workspace’s list of requests.

The values are exact, with no domain, workspace prefix, query string or fragment. In path mode, always use redirect=/changelog or redirect=/roadmap: pealHQ adds /w/{slug} to the destination itself. External URLs and arbitrary paths are not followed. redirect is a callback parameter, not a JWT field; it does not change the token validation rules.

The JWT expiry limits the time available to sign in; it is not the length of the portal session. Signing out of your application does not automatically close the pealHQ session.

Token contract

The format is base64url(header).base64url(payload).base64url(signature), without = padding. The signature is the binary HMAC SHA-256 of header_encode.payload_encode, computed with the shared secret, then Base64URL-encoded.

Use exactly this header, with the keys in this order and no additional fields:

{"alg":"HS256","typ":"JWT"}

The current verifier requires this order (alg, then typ) and only these two fields. If you use a JWT library, check the header it produces; do not add a kid.

All of the following fields are required:

FieldTypeExpected value
audStringExact workspace slug, for example acme. It is neither a URL nor an array.
subNon-empty stringStable identifier of the user in your application, for example user-482. Convert numeric identifiers to strings.
emailStringValid, trusted email of the authenticated account.
nameNon-empty stringName displayed in the portal.
iatIntegerUnix issue time in seconds, without milliseconds.
expIntegerUnix expiry time in seconds, later than the issue time and the time of receipt.
jtiNon-empty stringUnique random identifier for each sign-in attempt, for example a UUID.

The duration exp - iat must not exceed 120 seconds. The examples use 60 seconds. The issue time may be at most 5 seconds ahead of the pealHQ server; synchronise your servers’ clocks.

A token can only be used once. Generate a new jti and a new token for every click or new attempt. A validated token may be consumed even if an account-matching error occurs afterwards.

Do not use an admin or role field to grant rights: only sub, email and name are used to identify the customer after validation.

PHP example

This function works without a JWT library. Call it from a server route that has already authenticated and authorised the user. The id, email and name keys come from your accounts database, never from parameters freely supplied by the browser.

<?php

function pealSsoUrl(array $user, string $redirect = '/requests'): string
{
    $callback = getenv('PEAL_SSO_CALLBACK_URL');
    $audience = getenv('PEAL_SSO_AUDIENCE');
    $secret = getenv('PEAL_SSO_SECRET');

    if (! $callback || ! $audience || ! $secret || strlen($secret) < 32) {
        throw new RuntimeException('Configuration SSO pealHQ manquante ou invalide.');
    }

    $encode = static fn (string $value): string =>
        rtrim(strtr(base64_encode($value), '+/', '-_'), '=');

    $now = time();
    $header = $encode(json_encode(['alg' => 'HS256', 'typ' => 'JWT'], JSON_THROW_ON_ERROR));
    $payload = $encode(json_encode([
        'aud' => $audience,
        'sub' => (string) $user['id'],
        'email' => $user['email'],
        'name' => $user['name'],
        'iat' => $now,
        'exp' => $now + 60,
        'jti' => bin2hex(random_bytes(16)),
    ], JSON_THROW_ON_ERROR));
    $signature = $encode(hash_hmac('sha256', "$header.$payload", $secret, true));
    $token = "$header.$payload.$signature";
    $separator = str_contains($callback, '?') ? '&' : '?';

    return $callback.$separator.http_build_query([
        'token' => $token,
        'redirect' => $redirect,
    ], '', '&', PHP_QUERY_RFC3986);
}

In your controller, after checking the session, redirect to the returned URL: return redirect()->away(pealSsoUrl($user)); in Laravel (convert your model to an array), or header('Location: '.pealSsoUrl($user), true, 302); exit; in plain PHP. If your framework caches environment variables, inject the values through its configuration system rather than getenv.

To open the updates, call pealSsoUrl($user, '/changelog'); for the roadmap, pealSsoUrl($user, '/roadmap').

Node.js example

This ESM module uses only node:crypto. Keep it on the server side, in a route accessible to a user who is already authenticated and authorised.

import { createHmac, randomUUID } from 'node:crypto';

export function pealSsoUrl(user, redirect = '/requests') {
    const callback = process.env.PEAL_SSO_CALLBACK_URL;
    const audience = process.env.PEAL_SSO_AUDIENCE;
    const secret = process.env.PEAL_SSO_SECRET;

    if (!callback || !audience || !secret || secret.length < 32) {
        throw new Error('Configuration SSO pealHQ manquante ou invalide.');
    }

    const encode = (value) => Buffer.from(JSON.stringify(value)).toString('base64url');
    const now = Math.floor(Date.now() / 1000);
    const header = encode({ alg: 'HS256', typ: 'JWT' });
    const payload = encode({
        aud: audience,
        sub: String(user.id),
        email: user.email,
        name: user.name,
        iat: now,
        exp: now + 60,
        jti: randomUUID(),
    });
    const signature = createHmac('sha256', secret)
        .update(`${header}.${payload}`)
        .digest('base64url');
    const url = new URL(callback);
    url.searchParams.set('token', `${header}.${payload}.${signature}`);
    url.searchParams.set('redirect', redirect);

    return url.toString();
}

For example, in an Express controller protected by your authentication middleware: res.redirect(302, pealSsoUrl(req.user));. Adapt the property names to your user model. The secret and the signing function must never be included in the JavaScript bundle sent to the browser.

Use pealSsoUrl(req.user, '/changelog') or pealSsoUrl(req.user, '/roadmap') to choose the landing page.

Identity and existing accounts

pealHQ first looks for a customer with the same sub in the workspace, then for a customer with the same email. An existing account with this email can be linked to SSO if it is not already linked to another SSO identifier. Otherwise, a new customer account is created.

The name and email are updated at every sign-in. Keep the sub stable when the email changes, and never reuse a deleted user’s identifier for another person. Your server must guarantee that the user controls the email sent: this matching can give access to a portal account and to the rights of a team member already authorised in this workspace.

If the identifier and the email point to two different accounts, or if the email already belongs to another SSO identifier, the sign-in is refused. Correct the identity in your application or have the accounts concerned reviewed before trying again with a new token.

Troubleshoot an error

The callback is a sign-in page with a redirect, not a JSON API. The text displayed may be generic; the messages below correspond to the rejection causes on the server side.

StatusPossible causeCheck
403Missing SSO token.Send the JWT in the token query parameter.
403SSO is not configured for this organization.Enable SSO and retrieve the secret for the right workspace.
403Invalid SSO token.Check the secret, HS256, the order of the header fields and the Base64URL encoding without padding.
403Invalid or expired SSO token.Check the audience, the required fields, the types and the dates in seconds. Generate a fresh token.
403SSO token has already been used.Start again from your application with a new jti. Do not reload an old callback URL.
403SSO identity conflicts with an existing account.Check the consistency between sub, email and existing accounts.
403Workspace suspendedCheck the workspace’s status with its administrator.
404SSO disabled, unknown workspace or incorrect URLUse the callback shown in the settings of the active workspace again.
429Too many attemptsRespect Retry-After before trying again with a fresh token. The callback is limited to 20 requests per minute.

Test your integration

In a test workspace configured for SSO:

  1. Sign in a test user: they should land on the list of requests with their customer identity.
  2. Sign them in again with a fresh token: no additional account should be created.
  3. Change their name or email while keeping the sub: check that the account is updated.
  4. Reuse the same token, then try an expired token, a wrong audience and a wrong secret: each must be refused.
  5. Check that a user who is not authenticated in your application cannot obtain a token, and that no identity field is accepted directly from unverified user input.
  6. With an ordinary customer, check that the Admin button is absent and that admin actions are refused. With a member who is already authorised, check direct access to the workspace admin and team comments, with no access to other workspaces or to the platform admin.
  7. Sign out from the portal, then from the admin area: both access points for the workspace must be closed.

Protect and rotate the secret

Use HTTPS. Store the secret in your backend’s private configuration. A signed JWT is readable: it is not encrypted. Avoid logging URLs containing token, and do not share a real secret or token in a ticket or a third-party diagnostic tool. For an agent, use fictitious values and inject the secret at deployment.

The Regenerate secret button immediately invalidates tokens signed with the old secret. Update your backend at the same time; there is no overlap period. Rotating the secret does not close workspace sessions that are already open.

For another guide or its version intended for agents, see the documentation index and the Markdown index.