Authentication & API Keys
Authenticate with the AsPeekIt API using JWT tokens (with optional MFA), OIDC single sign-on token exchange, scoped API tokens for integrations, or agent and relay API keys.
Base URL
All API endpoints are served under the /api/v1/ prefix. Use the fully qualified URL of your AsPeekIt instance followed by the API path. For example, if your instance is hosted at https://idp.example.com, the full base URL is https://idp.example.com/api/v1/.
# Base URL for all API requests
https://<your-idp-host>/api/v1/JWT Authentication
The primary authentication mechanism for user-facing API calls is JSON Web Tokens (JWT). To obtain a token pair, send a POST request to the token endpoint with your username and password. The response includes an access token for authorizing requests and a refresh token for obtaining new access tokens without re-authenticating. When the user has MFA enabled and the request has no totp_code, the response is {"mfa_required": true}: send the same request again with totp_code (a TOTP code or a single-use backup code).
# Obtain a token pair
curl -X POST https://idp.example.com/api/v1/auth/token/ \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "your-password"}'
# With MFA enabled: first answer {"mfa_required": true}, then
# -d '{"username": "admin", "password": "your-password", "totp_code": "123456"}'
# Response
{
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Token Lifetimes & Rotation
Access and refresh tokens have different lifetimes to balance security and convenience. When a refresh token is used, the old refresh token is immediately blacklisted and a new pair is issued. This rotation strategy limits the window of exposure if a token is compromised.
- Access token lifetime: 1 hour
- Refresh token lifetime: 7 days
- Token rotation: each refresh request issues a new access and refresh token pair
- Blacklisting: used refresh tokens are added to a server-side blacklist and cannot be reused
Using the Access Token
Include the access token in the Authorization header of every API request using the Bearer scheme. If the token is expired or invalid, the API returns a 401 Unauthorized response.
# Authorize a request with the access token
curl -X GET https://idp.example.com/api/v1/assets/ \
-H "Authorization: Bearer {access_token}"API Tokens for Integrations
Scripts, CLIs and CI pipelines should not log in as a person. An admin creates a scoped, expiring API token for them (for a user or a dedicated service account) and the integration sends it as Authorization: Token <value>. Tokens are accepted only on the endpoints their scopes (read:inventory, read:security, write:security, write:sbom) open; see API Tokens (/docs/api/api-tokens) for scopes, endpoints and revocation.
curl https://idp.example.com/api/v1/assets/ \
-H "Authorization: Token idpt_..."Refreshing an Access Token
When your access token expires, use the refresh token to obtain a new token pair without requiring the user to log in again. Send a POST request to the refresh endpoint with the current refresh token.
Note: Store the new refresh token from the response. The previous refresh token is blacklisted immediately and cannot be used again.
# Refresh the token pair
curl -X POST https://idp.example.com/api/v1/auth/token/refresh/ \
-H "Content-Type: application/json" \
-d '{"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}'
# Response
{
"access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Logout (Token Blacklisting)
To log out, send the current refresh token to POST /api/v1/auth/logout/. The server blacklists it so it can no longer be used to obtain new access tokens. The access token remains valid until it naturally expires, so clients must discard both tokens locally. The web UI does this automatically and signs out every open tab.
# Log out (blacklist the refresh token)
curl -X POST https://idp.example.com/api/v1/auth/logout/ \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-d '{"refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}'OIDC Single Sign-On
Single sign-on works as a token exchange: the client signs the user in with the identity provider, then sends the provider-issued ID token to POST /api/v1/auth/oidc/exchange/ with the provider name. The backend verifies the signature against the provider JWKS and checks iss and aud (and tid for Azure AD) before using any claim, then answers with an AsPeekIt token pair like the password login. Providers: azure-ad (AZURE_AD_CLIENT_ID and a single-tenant AZURE_AD_TENANT_ID), google (GOOGLE_CLIENT_ID, optional GOOGLE_HOSTED_DOMAIN) and okta (OKTA_CLIENT_ID and OKTA_ISSUER).
- A provider is enabled only when its settings are present; with none configured the endpoint answers 404 "SSO is not configured.", an unknown provider 400.
- Azure AD and Okta groups (or Azure app roles) named OIDC_ADMIN_GROUP (default IDP-Admin) and OIDC_STAFF_GROUP (default IDP-Staff) map to the AsPeekIt roles; users in neither are set to viewer at every SSO login. Google sends no groups: roles are managed in AsPeekIt.
- Rate limited by THROTTLE_AUTH_OIDC_RATE (default 10/minute). Logins and failures are written to the audit log.
curl -X POST https://idp.example.com/api/v1/auth/oidc/exchange/ \
-H "Content-Type: application/json" \
-d '{"provider": "azure-ad", "token": "<provider ID token>"}'User Registration
Self-registration is disabled by default (ALLOW_SELF_REGISTRATION=false): user accounts are created by an administrator (User Management in the Platform section of the navigation, or POST /api/v1/auth/admin/users/create/). The register endpoint below only accepts requests when self-registration is enabled on the server, and self-registered accounts are always viewers.
POST /api/v1/auth/register/ # only when self-registration is enabled
# Example
curl -X POST https://idp.example.com/api/v1/auth/register/ \
-H "Content-Type: application/json" \
-d '{
"username": "newuser",
"email": "user@example.com",
"password": "secure-password",
"password_confirm": "secure-password"
}'User Profile
Retrieve or update the authenticated user's profile. GET returns id, username, email, first_name, last_name, full_name, job_title, department, phone, avatar, preferences, teams, role, is_active, date_joined and last_login; PATCH updates the editable ones (role, teams and is_active are read-only). preferences are merged into the stored ones, not replaced. GET /api/v1/auth/me/ returns the current user too.
# Get current user profile
curl -X GET https://idp.example.com/api/v1/auth/profile/ \
-H "Authorization: Bearer {access_token}"
# Update profile
curl -X PATCH https://idp.example.com/api/v1/auth/profile/ \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-d '{"email": "newemail@example.com"}'Change Password
Change the password for the currently authenticated user. Requires the current password and the new one twice. Every outstanding token of the user is revoked and the response carries a fresh token pair.
POST /api/v1/auth/password/change/
# Example
curl -X POST https://idp.example.com/api/v1/auth/password/change/ \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-d '{
"old_password": "current-password",
"new_password": "new-secure-password",
"new_password_confirm": "new-secure-password"
}'Agent Authentication
AsPeekIt agents (installed on hosts for process-level discovery) use a separate authentication mechanism based on API keys. Instead of JWT tokens, agents authenticate by including two custom headers in every request: X-Agent-ID to identify the agent instance, and X-API-Key to prove its identity. Agent keys are managed on the Agents page (Discovery section); see Agent Configuration > API Key Management and Agent Enrollment & mTLS. Relays authenticate the same way with X-Relay-ID and an idpr_ key (Relay Overview).
# Agent authentication headers (health check, answers "authenticated": true with a valid key)
curl https://idp.example.com/api/v1/agent/health/ \
-H "X-Agent-ID: agent-hostname-001" \
-H "X-API-Key: idpk_..."
# Agents send their reports to POST /api/v1/agent/data/ with the same headersAPI Key Format & Storage
Agent API keys follow a specific format for easy identification and secure storage. Each key is prefixed with idpk_ followed by 64 URL-safe characters (48 random bytes). The raw key is shown to the administrator exactly once at creation time. AsPeekIt stores only the SHA-256 hash of the key in the database, so the original key cannot be recovered if lost.
- Format: idpk_ followed by 64 URL-safe characters; the first 8 characters of the key are kept as its visible prefix
- Storage: only the SHA-256 hash is persisted in the database
- The plaintext key is displayed once during creation and cannot be retrieved afterwards
- If a key is lost, generate a new one and update the agent configuration
Warning: Copy the API key immediately when it is generated. AsPeekIt does not store the plaintext key and cannot display it again.
Error Responses
Authentication failures return standard HTTP error codes with a JSON body describing the issue.
- 401 Unauthorized: missing, expired, or invalid access token
- 401 Unauthorized: invalid or missing agent API key headers
- 401 Unauthorized: unknown, revoked or expired API token (Authorization: Token ...)
- 403 Forbidden: valid token but insufficient permissions for the requested resource, or an API token used on an endpoint or method its scopes do not open
- 400 Bad Request: malformed token request (missing username, password, or refresh token)
// Example 401 response
{
"detail": "Given token not valid for any token type",
"code": "token_not_valid",
"messages": [
{
"token_class": "AccessToken",
"token_type": "access",
"message": "Token is invalid or expired"
}
]
}