Authentication Methods
In the Graphistry 2.0 REST API, authentication is crucial for security and access control. Currently, there are three methods to obtain JWT tokens:
- Username and Password
- Personal API Key
- Single Sign-On (SSO)
1. Password Authentication
Use your account credentials to get a short-lived token (~1 hour). This token is required for performing REST API actions. Tokens are valid for up to 24 hours, requiring daily re-login with full credentials. For more information, see Personal API Key Authentication and Single Sign-On (SSO) Authentication.
2. Personal API Key Authentication
To authenticate using a personal API key:
- Navigate to your profile menu and select "Manage API Keys".
- Generate a Personal Key ID and Secret Key. Note: The Personal Secret Key will not be visible again after leaving this screen.
- Use the Personal Key ID and Secret Key to authenticate by making a POST request with the following format:
curl -X POST -H "Authorization: PersonalKey ${PERSONAL_KEY_ID}:${PERSONAL_KEY_SECRET}" https://${GRAPHISTRY_HOST}/api/v2/auth/pkey/jwt/
This request will return a JWT token that can be used for subsequent API requests.
3. Global Single Sign-On (SSO)
SSO authentication redirects you to the site-wide SSO system for login.
4. Single Sign-On (SSO) with Organization (IDP)
For organizations using IDP (Identity Provider) with SSO, the authentication process involves two steps and two API calls:
- Initiate SSO Authentication: The first step is to initiate the SSO authentication process for your organization. This is done by making a GET request to the SSO login API endpoint. This request will redirect you to the organization's SSO login page.
- Retrieve the JWT Token: After successfully logging in through the SSO system, you will receive a response that includes a 'state' parameter. This 'state' is a unique identifier for your session. You then use this 'state' to make a second API call to retrieve your JWT token.
5. Single-Use Token Gateway (Admin Only)
The Single-Use Token Gateway enables one-time token-based access to Graphistry datasets for external, unauthenticated users. This authentication method is restricted to administrators (staff OR superuser) and provides temporary access without requiring full account creation.
Use Case: Admins can generate secure, single-use URLs for external users to access specific datasets without creating permanent accounts or sharing credentials.
Flow:
- Admin calls
GET /api/v2/generate/single-use-url/?username=any_username&dataset_id=DATASET_IDwith Bearer token - System returns magic login URL:
{"single_use_url": "https://domain/magic-login/?sst=TOKEN"} - Admin sends magic login URL to external user
- External user clicks the magic login link
- User gains temporary access to the specified dataset only
- Admin can immediately revoke access using
GET /api/v2/logout-user/username/to force logout and remove all permissions
Security Features:
- One-time use tokens (expire after first use)
- Limited access scope (only target dataset)
- Dual-layer time expiration (see Configuration below)
- Admin-controlled revocation (force logout active users)
Access Control:
Once external users click the magic login link, they gain active sessions until natural expiry. Admins can use the logout endpoint to immediately revoke access for security purposes - useful for ending demos, responding to security concerns, or removing access when collaboration ends.
Configuration
The following settings control the behavior of the Single-Use Token Gateway:
| Setting | Type | Default | Description |
|---|---|---|---|
SESAME_TOKEN_NAME |
string | sst |
Name of the query parameter used to pass the sesame token (e.g., ?sst=abc123) |
SESAME_MAX_AGE |
int | 3600 |
Maximum lifespan of a sesame token in seconds (default: 1 hour) |
SESAME_ONE_TIME |
bool | True |
When set to True, each token is valid only once and expires after first use. Django-sesame enforces this by updating the user's last login date |
COOKIE_SECURE |
bool | False (auto-True if DJANGO_SECURE_SSL_REDIRECT=True) |
Ensures session, CSRF, and JWT auth cookies are only sent over HTTPS. Required when embedding in a cross-origin <iframe> to preserve auth across domains. Auto-enabled when the operator has already opted into HTTPS-only via DJANGO_SECURE_SSL_REDIRECT=True; can still be set explicitly to override. See Cross-Origin Iframe Embedding below. |
COOKIE_SAMESITE |
string | None if COOKIE_SECURE=True, else Lax |
Controls the SameSite attribute on session, CSRF, and JWT cookies. Auto-derives to None when COOKIE_SECURE=True (the cross-origin iframe embedding case) and Lax otherwise. COOKIE_SAMESITE=None requires COOKIE_SECURE=True -- browsers reject SameSite=None cookies that are not Secure, and this combination is rejected at startup with ImproperlyConfigured. See Cross-Origin Iframe Embedding below. |
Note: In addition to the configurable sesame token settings above, magic links have a hardcoded 7-day database record expiration. ShareLinkUser records are automatically cleaned up after 7 days from generation, making magic links completely invalid regardless of usage.
Cross-Origin Iframe Embedding
To embed Graphistry visualizations in an <iframe> on a different origin (for example, embedding into Louie or another web app), the Graphistry server must issue session cookies with SameSite=None; Secure. Otherwise the browser will drop the auth cookies inside the embedded iframe and the user will see an auth loop or a "This content is blocked" message.
Set both flags in the Graphistry server's environment configuration:
COOKIE_SECURE=true
COOKIE_SAMESITE=None
Notes:
COOKIE_SECURE=truerequires Graphistry to be served over HTTPS. TLS termination at the reverse proxy or ingress (e.g. Caddy, nginx-ingress, k8s ingress controller) is sufficient.- If
DJANGO_SECURE_SSL_REDIRECT=trueis already set (the operator has opted into HTTPS-only mode),COOKIE_SECUREauto-derives totrue; no need to set it twice. - When TLS terminates at an upstream load balancer or ingress controller (common in Kubernetes), set
COOKIE_SECURE=trueexplicitly and leaveDJANGO_SECURE_SSL_REDIRECTunset. This stamps cookies asSecurewithout making Django itself issue HTTP-to-HTTPS redirects, which can interfere with LB health checks. - If
COOKIE_SECURE=trueandCOOKIE_SAMESITEis unset, it auto-derives toNone; setting it explicitly is recommended for clarity. - Misconfiguration guard: setting
COOKIE_SAMESITE=None(case-insensitive) withoutCOOKIE_SECURE=TrueraisesImproperlyConfiguredat startup, because browsers rejectSameSite=Nonecookies that are notSecure. - These flags apply to all three auth cookies:
sessionid,csrftoken, andgraphistry_jwt. - The embedding host must also allow the Graphistry origin in its CSP
frame-srcandchild-src. For Louie embedding, see the Graphistry Iframe Blocked in Louie runbook.
HSTS note when re-testing on plain HTTP: if a previous HTTPS visit set HSTS (Graphistry production defaults SECURE_HSTS_SECONDS), the browser will auto-upgrade http:// URLs for that hostname for the cache TTL. If a plain-HTTP regression test silently redirects to HTTPS, clear HSTS for the host via chrome://net-internals/#hsts (or the Firefox equivalent).
Verify in the browser DevTools, under Application > Cookies on the Graphistry host. Check all three cookies individually. They are written by different code paths and can disagree if misconfigured:
| Cookie | Working (cross-origin embed) | Failing (cookies dropped in iframe) |
|---|---|---|
sessionid |
SameSite=None; Secure |
SameSite=Lax or missing Secure |
csrftoken |
SameSite=None; Secure |
SameSite=Lax or missing Secure |
graphistry_jwt |
SameSite=None; Secure |
SameSite=Lax or missing Secure |
All three must match. If graphistry_jwt disagrees with the other two, the JWT cookie's SameSite wiring may be missing; see JWT_AUTH in config/settings/base.py.
Flow Diagram
Admin → Generate URL
→ Send the URL to User
User → /magic-login?sesame=... → Logs in
→ /graph/graph.html?dataset=... (auto)
Admin → /logout-user/<username>/ → revokes session
User → Logout
Using REST API for Authentication
Below are examples of REST API calls for each authentication method:
| Route | Method | Headers | Parameters | Return |
|---|---|---|---|---|
api/v2/auth/pkey/jwt/ |
POST | Authorization: PersonalKey PERSONAL_KEY_ID:PERSONAL_KEY_SECRET | Personal Key ID, Personal Secret Key | {"token": str} |
Input:
Note: Replace "YOUR_ORG_NAME" with the actual name of your organization. This parameter is optional. |
||||
api/v2/g/sso/oidc/login |
GET | N/A | N/A | Redirect to SSO login page |
Input:
|
||||
sso/oidc/login/idp_name/ |
GET | N/A | N/A | Redirect to SSO login page |
Input:
|
||||
/sso/oidc/jwt/{state}/ |
GET | N/A | N/A | N/A |
Input:
|
||||
For further details and language-specific implementations, please refer to our Python client library documentation.