Integrate single sign-on (SSO) into your application so sub-merchants can access Stax without entering separate login credentials.
Follow this developer reference to request a temporary authentication token on your server and construct an SSO URL. Your merchants can use that URL to complete onboarding or access Stax features from your application.
Ephemeral Authentication Tokens
An ephemeral authentication token is a temporary credential that expires after 24 hours. Use it to authenticate API calls from clients or browsers while keeping your long-term API key on your server. Treat the temporary token as a sensitive credential too: anyone who obtains it can use its access until it expires.
Key Benefits
Keep your long-term API Key secure on your server.
Tokens expire after 24 hours, reducing the risk if compromised.
Use tokens for mobile SDKs or to enable Single Sign-On (SSO) for sub-merchants.
Use Cases
Request a token for a specific merchant user by providing user_id or user_email. Use that token to construct an SSO URL that opens Stax without a separate login prompt.
Use ephemeral tokens with the mobile SDKs to authenticate API calls from your mobile application. Request tokens on your server and pass only the temporary token to the app; keep your long-term API key on your server.
Implementing Ephemeral Tokens
Step 1: Generate an API Key
Generate a merchant API key so your server can request temporary tokens without exposing the key to your application’s users.
- Log in to your Stax account and select the production or sandbox merchant account you want to use.
- Open Apps > API keys > Launch > + New Key to generate an API key.
- Copy the API key and store it securely on your server. Do not embed it in browser or mobile code.
For a partner integration, you can instead create your merchant's API key through the API.
Step 2: Request an Ephemeral Token
For SSO, send GET https://apiprod.fattlabs.com/ephemeral from your server with your merchant API key in the Authorization: Bearer header. Specify the merchant user with either user_email or user_id; the example in Step 3 uses user_email so you do not need to look up an ID.
| Parameter | Type | Requirement and default |
|---|---|---|
Authorization header | String | Required. Use Bearer followed by your merchant API key. No default. |
user_email query parameter | String | Supply this or user_id for SSO. Use the existing merchant user's email address and URL-encode it. No default. |
user_id query parameter | String | Alternative to user_email. Use the Stax user ID returned when you create the merchant's user account. No default. |
Optional: Authenticate as your own user without SSO. Omit both query parameters to request a token for the user associated with your API key. Do not use this mode for SSO, which requires a specific user.
Step 3: Request a Token and Build SSO URLs
- Complete the merchant and user creation steps in SSO to Stax > Prerequisites below.
- Run Python 3 on your server. This example uses only the Python standard library; do not run it in a browser or mobile application.
- Enter the merchant API key from Apps > API keys > Launch and the email address you supplied when creating the merchant's Stax user. The prompts hide both values.
import getpass
import json
import sys
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode
from urllib.request import Request, urlopen
def main():
api_key = getpass.getpass("Merchant API key: ").strip()
user_email = getpass.getpass("Merchant user's email: ").strip()
if not api_key or not user_email:
raise ValueError("Enter both the API key and the merchant user's email.")
query = urlencode({"user_email": user_email})
request = Request(
"https://apiprod.fattlabs.com/ephemeral?" + query,
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.")
# Encode each query value once, including the nested redirect path.
pay_query = urlencode({"jwt[]": token})
signup_query = urlencode({
"jwt[]": token,
"redirect": "application/review",
})
print("Ephemeral token received (valid for 24 hours).")
print("Stax Pay SSO URL: https://app.staxpayments.com/#/sso?" + pay_query)
print("Signup SSO URL: https://signup.staxpayments.com/#/sso?" + signup_query)
if __name__ == "__main__":
try:
main()
except HTTPError as error:
print(
"Token request failed (HTTP " + str(error.code)
+ "). Check the API key, merchant team, and user email.",
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):
print("Missing input, unreadable response, or missing token. Check the request and response format.", file=sys.stderr)
sys.exit(1)
except (EOFError, KeyboardInterrupt):
print("Token request canceled.", file=sys.stderr)
sys.exit(1)On success, the first output line is:
Ephemeral token received (valid for 24 hours).The next two lines contain SSO URLs built with the returned token. Keep this output private: the URLs grant access. In your application, pass the appropriate URL only to the intended merchant user rather than writing it to shared logs.
For subsequent API calls, set the Authorization header to Bearer followed by the returned token. If the request fails or the response lacks a token, the script exits with an error instead of constructing an unusable SSO URL.
Step 4: Open Stax with SSO
- Use the ephemeral token to facilitate SSO for sub-merchants.
- Redirect the user to the Stax platform with the token to log them in automatically.
SSO to Stax
Send your merchants to Stax via SSO to use reports and functionality that you haven't added to your platform.
Merchants can use Stax to:
- Perform voids and refunds via their payments list.
- View and download their deposits.
- View their disputes.
- Download monthly processing statements.
Add a button to your application that opens the generated SSO URL for the intended merchant user. The button belongs to your application; it is not a Stax Dashboard control.
Prerequisites
You must complete the following steps to implement SSO into your software.
- Create a Merchant in Stax to represent one of your sub-merchants.
- Create your merchant's API Key.
- Create a Stax user account using the merchant's API key.
Request SSO into Stax
Construct an SSO URL for Stax Pay or the Stax Signup Pages and use it as the destination for your application's button. After authentication, Stax directs the user to the specified page.
- Request an ephemeral authentication token for the merchant user, as shown in Steps 2–3 above.
- Begin constructing the URL by specifying the app's SSO page.
- For Stax, https://app.staxpayments.com/#/sso/
- For the Stax Signup Pages, https://signup.staxpayments.com/#/sso/
- Pass the returned ephemeral token as the
jwt[]URL query parameter. Use the actual token rather than a placeholder; the Step 3 example URL-encodes this value for you. - Optional: Set a redirect query parameter to choose a destination within Stax Pay or the Stax Signup Pages. URL-encode the destination, including any query parameters inside it. If you omit
loginRedirectorredirect, Stax opens the app's homepage.
Stax Signup Pages
- URL parameter is named
redirect - Example: Stax Signup Pages Review Page
&redirect=application%2Freview
Stax Pay
- URL parameter is named
loginRedirect - Example: Stax Pay Deposit Report page, with start- and end-date parameters
&loginRedirect=report%2Fdeposit-report%3FstartDate%3D2020-01-01%252000%253A00%253A00%26endDate%3D2020-09-25%252023%253A59%253A59%26timezone%3DEDT%26order%3DDESC%26page%3D1
Build the Full SSO URL
Run the Step 3 example to generate complete URLs with a real token. It generates a Stax Pay URL that opens the homepage and a Stax Signup Pages URL that opens application/review.
To open the deposit report instead, add loginRedirect to the example's pay_query dictionary with the unencoded destination path and query string. Let urlencode encode it; do not pass an already encoded value to urlencode.
Protect Credentials and Handle Token Expiration
Required for this integration: Keep the API key on your server, use HTTPS, and specify a merchant user when requesting an SSO token. Request a new token after expiration; an expired token cannot authenticate a request.
These security practices support your compliance efforts; they do not establish compliance. Consult your legal team regarding specific requirements.
Never expose your long-term API Key to clients, browsers, or mobile applications. Always keep API Keys secured on your server.
Make API calls and open SSO URLs over HTTPS to protect credentials in transit.
Request a new ephemeral token from your server when the current token expires after 24 hours. Do not retry with the expired token.
If a token expires, request a new one before retrying. For permission errors, verify that the user belongs to the merchant team before requesting another token.
Common Errors and Troubleshooting
Permission Errors
Error Message: "You do not have permission to request tokens for other users."
Cause: Attempting to generate an ephemeral token for a Stax Connect level user or a user not on the same team.
Solution: Request tokens only for non-Stax Connect users on the same merchant team.
Invalid API Key
Error Message: "Invalid API Key."
Cause: The API Key provided in the Authorization header is invalid or expired.
Solution: Verify that you are using a valid, active API Key generated from your Stax account.
Missing User Parameters for SSO
Issue: Attempting to perform SSO without specifying user_id or user_email.
Solution: Always include user_id or user_email in the URL parameters when generating an ephemeral token for SSO.
Token Expiration
Error Message: "Token has expired."
Cause: The ephemeral token has expired after 24 hours.
Solution: Generate a new ephemeral token using your API Key.
Optional: Add Security Monitoring and Maintenance
The following measures are recommended in addition to the required integration steps above.
Rotate API keys periodically to limit exposure if a key is compromised. Update the key in your server configuration when you rotate it.
In client applications, implement logic to handle token expiration and request a new ephemeral token when needed.
Only grant the necessary permissions required for the client application. Avoid unnecessary privileges to reduce security risks.
Keep track of API usage and monitor for any unusual activity. Set up alerts for failed authentication attempts or other anomalies.
Verify the SSO Result
- Run the Step 3 example and confirm that it reports
Ephemeral token received (valid for 24 hours).and generates both SSO URLs. - Open the appropriate URL in a browser as the intended merchant user. Stax should authenticate that user without a separate login prompt.
- Confirm the destination: the example's Stax Pay URL opens the homepage, and its Stax Signup Pages URL opens
application/review. If you supplied another redirect, confirm that Stax opens that page instead.
If authentication fails, check the merchant user and API key against Common Errors and Troubleshooting above. Request a new token if more than 24 hours have passed since issuance.
