Written for: For developers
Sign users in with web tickets
Web tickets sign the people who use your product in to Astrato without an Astrato password. Your backend vouches for a person by email address, Astrato returns a one-time ticket, and the person’s browser redeems it for an Astrato session. This page is the reference for those requests. For when to use web tickets rather than single sign-on, and the embed settings they work with, see Sign your own users in.
The public repository astrato-io/astrato-oem-integration-example has a working backend and page. To stay short, it takes the email address it is given and does not sign the person in. In your product, authenticate the person first and take the ticket’s email address from that verified identity, never from the browser.
Before you start
Section titled “Before you start”- The OEM credentials. An administrator enables the OEM management API on the General tab of System settings and copies the Client ID and Client secret. The secret is shown only when the API is enabled or someone selects Rotate; it cannot be shown again.
- A backend you control. The client ID and secret, and the access token they return, can impersonate every member of the workspace. Send the token and ticket requests from your server only, and give the browser nothing but the ticket.
- Groups for the content. A person signed in with a ticket sees what their groups allow. Create the groups that grant access to the content your users open; see Manage groups and assignment rules.
The examples use https://app.astrato.io. If your organization uses another Astrato address, use
that instead.
How the flow works
Section titled “How the flow works”| Step | Request | Sent by | Authenticated with | Result |
|---|---|---|---|---|
| 1 | POST /auth/proxy/m2m/token |
Your backend | Client ID and secret | An access token, valid for 10 minutes |
| 2 | POST /oem/setup |
Your backend | The access token | A ticket, valid for 60 seconds |
| 3 | GET /auth/proxy/oem/ticket/<ticket>?embed |
The browser | The ticket | An Astrato session in that browser |
You can reuse one access token for several ticket requests until it expires. Each ticket works once, so request a new one for every sign-in.
Get an access token
Section titled “Get an access token”From your backend, send the client ID and secret:
curl https://app.astrato.io/auth/proxy/m2m/token \ --header 'Content-Type: application/json' \ --data '{ "clientId": "<client ID>", "clientSecret": "<client secret>" }'The response:
{ "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", "expires_in": 1762866000000}| Field | Meaning |
|---|---|
access_token |
Send it as Authorization: Bearer <access_token> on the ticket request. |
expires_in |
When the token expires, as a Unix time in milliseconds, not a number of seconds from now. |
The body must contain clientId and clientSecret and nothing else. A wrong client ID or secret
returns 400 with code 11900 and the message Invalid client id or client secret.
Request a ticket
Section titled “Request a ticket”From your backend, send the person’s email address with the access token:
curl https://app.astrato.io/oem/setup \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <access_token>' \ --data '{ "email": "viewer@example.com", "name": "Sam Viewer", "groupNames": ["Customer viewers"] }'The response:
{ "ticket": "3f1c2a9e-5b7d-4c1e-9a2f-8d6b4e0c7a51"}| Field | Required | Meaning |
|---|---|---|
email |
Yes | The person to sign in. A ticket without one is accepted but cannot be redeemed. |
name |
No | The display name for this session, and for the account if Astrato creates it. |
groupIds |
No | IDs of groups in your workspace whose permissions the person gets for this session. |
groupNames |
No | Names of groups in your workspace, used the same way as groupIds. You can send both. |
filterParameters |
No | Values for row-level filters, for this session. See Filter rows per session. |
applyPendingInvites |
No | true creates a new account from the most recent pending invitation to that address. Default false. |
Unknown fields make the request fail with 400.
What happens to the person’s account
Section titled “What happens to the person’s account”A person with no account gets one when the ticket is redeemed. The new account has the
Viewer role and belongs to no group, unless you send applyPendingInvites: true and a pending
invitation to that address exists: then the account takes the role and groups of the most recent
invitation. Any pending invitations to that address in your workspace are removed at that point,
whether or not you apply them.
Groups apply to the session only. The groups you send are added to the person’s own group memberships for the session the ticket creates. They do not change the memberships stored on the account; to change those, see Manage groups and assignment rules. To look up a group’s ID from your backend, see Find or create a group.
If the request fails
Section titled “If the request fails”| Status | Code | Message | Cause |
|---|---|---|---|
400 |
11119 |
Unknown groups membership requested |
A group ID or name does not exist in your workspace. The details list which ones. |
400 |
11006 |
User cannot be accessed by oem |
The address belongs to an account in another workspace. |
400 |
11902 |
Provided payload is too large |
The groups, counted as IDs, and filterParameters exceed 8,000 characters of JSON. |
400 |
— | Invalid email |
email is not a valid email address. |
A missing, invalid or expired access token is refused. Get a new token and send the request again.
Redeem the ticket in the browser
Section titled “Redeem the ticket in the browser”Send the ticket to the person’s browser, and have the browser request the ticket address within 60 seconds. Astrato looks the ticket up, deletes it so it cannot be used again, and signs that browser in. If the browser already had an Astrato session, the new one replaces it, so when a person switches to another customer or organization in your product, request a new ticket for them.
For an embed
Section titled “For an embed”Call the ticket address with the embed parameter from your page, with credentials, and insert
the iframe once it succeeds:
const response = await fetch(`https://app.astrato.io/auth/proxy/oem/ticket/${ticket}?embed`, { credentials: 'include',});if (!response.ok) throw new Error(`Ticket redemption failed: ${response.status}`);
const iframe = document.createElement('iframe');iframe.src = '<restricted embed link>';document.body.append(iframe);With embed, the ticket address redirects to Astrato’s embed sign-in, which sets the embedded
session and answers with an empty JSON object. The browser is also signed in to Astrato itself,
so the person can do there what the embed cannot. For the embed settings the iframe needs, see
Embed a dashboard; if the frame stays blank, see
If the frame is blank.
To open Astrato itself
Section titled “To open Astrato itself”Navigate the whole browser window, not a frame, to the ticket address without embed:
https://app.astrato.io/auth/proxy/oem/ticket/<ticket>Astrato signs the browser in and redirects to its home page. This is how a sign-in page you host signs people in to Astrato; see Use your own sign-in page.
If redemption fails
Section titled “If redemption fails”| Status | Code | Message | Cause |
|---|---|---|---|
400 |
— | Invalid ticket |
The ticket is unknown, already used or more than 60 seconds old. |
400 |
11006 |
User cannot be accessed by oem |
The address belongs to an account in another workspace. |
404 |
11106 |
User was not found |
The ticket was requested without an email. |
In each case, request a new ticket from your backend.
The session lasts a fixed time from sign-in, set for your Astrato environment, and activity does not extend it. When it ends, request a new ticket.
Filter rows per session
Section titled “Filter rows per session”filterParameters passes values to row-level filters for the session, in the same form as the
filter parameters stored on an account. Each key is
[<parameter name>].[<type>], and each value is a string, number, boolean or null:
{ "email": "viewer@example.com", "groupNames": ["Customer viewers"], "filterParameters": { "[org_id].[string]": "ORG-8700", "[min_amount].[float]": 100.5, "[region].[undefined]": null }}| Type | Effect |
|---|---|
string |
Text. A string can also feed a number, date or timestamp field. |
int |
Whole number. |
float |
Decimal number. |
boolean |
true or false. |
date |
Date. |
millisec |
A timestamp, as a whole number of Unix milliseconds. |
millisec_tz |
The same, for a timestamp-with-time-zone field. |
null |
The filter matches rows where the field has no value. |
undefined |
The filter that reads this parameter is not applied. |
Values sent with a ticket are added to any stored on the account. Where both set the same name and type, the ticket’s value is used for the session.
What a missing value does depends on where the filter is:
- In a workbook, a row-level filter whose parameter the session has no value for is not applied, so the person sees every row that filter would have hidden.
- In a semantic layer, a Pre-filter condition whose value is set to Parameter, and a
Custom SQL table’s
{name:type}token, both use their default when the session has no value. Set a default that matches no customer.
Send a value for every parameter your filters read, and use undefined only for people who must
see all rows, such as your own administrators.
Sign a browser out
Section titled “Sign a browser out”To end the Astrato session in the browser in front of you, navigate that browser to
https://app.astrato.io/auth/proxy/0/sign_out. It ends the session whose cookie the browser sends,
so it works only as a browser navigation; calling it from your server signs nobody out.
If people may later land on Astrato’s own sign-in page, you can show it without Astrato’s branding; see Hide Astrato branding on its sign-in page.
Related
Section titled “Related”- Embed a dashboard: where web tickets fit, and the embed settings they need.
- Users and groups API: create groups and add people to them from your backend.
- Authentication: how each Astrato client signs in.
- Integrate with Astrato: every interface Astrato offers.