Ephemeral Authentication Tokens

This endpoint accepts a request made with an API Key in the Authorization header and issues an ephemeral authentication token (expiring in 24 hours) in response.

Ephemeral Authentication Tokens

Request an ephemeral authentication token (a temporary credential valid for 24 hours) to authenticate subsequent API calls without sending your long-term API key each time. The token is a JSON Web Token (JWT), a signed credential that identifies the user making the request.

API Key Requirements
  • Generate an API key in your Stax merchant account: open Apps > API keys > Launch > + New Key.
  • Keep the API key on your server; do not embed it in browser or mobile code. Treat the temporary token as a sensitive credential too.
  • Send the API key in the Authorization header as Bearer followed by the key.

Request a Token for Your API Key's User

For standard API authentication, start without query parameters. This requests a token for the Stax user associated with your API key and avoids looking up a user ID. For single sign-on (SSO), which lets a user access Stax without entering separate login credentials, specify a user as described below instead.

  1. Run Python 3 on your server. This example uses only the Python standard library.
  2. Save the code below as request_ephemeral_token.py, then run python3 request_ephemeral_token.py.
  3. Enter your merchant API key from Apps > API keys > Launch at the hidden prompt.
import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen


def main():
    api_key = getpass.getpass("Merchant API key: ").strip()
    if not api_key:
        raise ValueError("Enter a nonempty merchant API key.")

    request = Request(
        "https://apiprod.fattlabs.com/ephemeral",
        headers={
            "Authorization": "Bearer " + api_key,
            "Accept": "application/json",
        },
        method="GET",
    )
    with urlopen(request, timeout=30) as response:
        payload = json.load(response)

    token = payload.get("token") if isinstance(payload, dict) else None
    if not isinstance(token, str) or not token.strip():
        raise ValueError("The response did not contain a nonempty token string.")

    # Keep credentials out of terminal output and shared logs.
    print("Ephemeral token received (valid for 24 hours).")
    # In your server application, pass this value to subsequent API requests.
    return token


if __name__ == "__main__":
    try:
        main()
    except HTTPError as error:
        if error.code == 422:
            message = "Request rejected (HTTP 422). Use a merchant API key, not an ephemeral token."
        else:
            message = "Token request failed (HTTP " + str(error.code) + ")."
        print(message, file=sys.stderr)
        sys.exit(1)
    except URLError:
        print("Could not reach Stax. Check server connectivity and retry.", file=sys.stderr)
        sys.exit(1)
    except (ValueError, OSError) as error:
        print("Token request failed: " + str(error), file=sys.stderr)
        sys.exit(1)
    except (EOFError, KeyboardInterrupt):
        print("Token request canceled.", file=sys.stderr)
        sys.exit(1)

On success, the script prints:

Ephemeral token received (valid for 24 hours).

The script validates that the response contains a nonempty token string without printing the credential. In your server application, use the returned token in subsequent API calls by setting the Authorization header to Bearer followed by that token. The script exits with an error if input is missing, the request fails, or the response is unreadable or lacks a token.

Optional: Compare Authentication Modes

Standard Authentication:

  • Omit both user_id and user_email to authenticate as the Stax user associated with your API key.
  • The endpoint sets that user as the JWT subject (the user identified by the token).
Important Note

This method is not suitable for SSO capabilities because SSO requires specifying a particular user.

Key Benefits

Temporary Access

Tokens expire in 24 hours for enhanced security.

Flexible Authentication

Support for both standard and user-specific token generation.

SSO Ready

Request a user-specific token for single sign-on.

Query Params
string

Provide the Stax User ID for whom the ephemeral token should be issued. Leave blank to issue the token for the API Key in the Authorization header.

string

Provide the URL-encoded email of the Stax User for whom the ephemeral token should be issued. Leave blank to issue the token for the API Key in the Authorization header.

Responses

Language
Credentials
Bearer
JWT
LoadingLoading…
Response
Click Try It! to start a request and see the response here! Or choose an example:
application/json