Skip to main content

Platform API: Authentication

Overview​

Every Platform API request is authenticated with a Bearer JWT in the Authorization header and authorized against the OAuth2 scopes carried in that token. There is no Basic Auth path and no API-key path for this API — the access token is the only credential.

Authorization: Bearer <access_token>

Two things must be true for a request to succeed:

  1. Authentication — the token's signature, expiry and issuer validate, and it carries an organization claim identifying the caller's organization.
  2. Authorization — the token's scope claim (or, in role mode, its roles expanded to scopes) satisfies the scope declared on that specific operation. Every operation page in this documentation lists its required scopes under an Authentication heading.

All operations are automatically scoped to the organization in the token. An organization ID is never read from a path, query or body parameter, so a token for one organization can never reach another organization's resources.

Authentication Modes​

The mode is selected once at startup with [platform_api.auth] mode. Only the selected mode's configuration section is read; the others are ignored.

ModeHow tokens are obtainedSignature verified withTypical use
fileThe built-in login endpoint issues RS256 JWTs for locally configured usersauth.jwt.public_key_fileQuickstart, air-gapped setup
external_tokenTokens are minted outside the Platform API by a trusted issuerauth.jwt.public_key_fileExisting token service
idpAn external Identity Provider's token endpointThe IDP's JWKS (auth.idp.jwks_url)Production (Asgardeo, Keycloak, Auth0, Entra ID, WSO2 IS)

Supported signing algorithms: RS256, RS384, RS512 (RSA) and, in IDP mode, ES256, ES384, ES512 (ECDSA). Symmetric (HS*) and unsigned (none) tokens are always rejected.

Tokens are validated against the IDP's JWKS endpoint. jwks_url and issuer are required.

[platform_api.auth]
mode = "idp"
scope_validation = true

[platform_api.auth.idp]
name = "asgardeo"
jwks_url = "https://accounts.example.com/oauth2/jwks"
issuer = ["https://accounts.example.com"] # list of accepted issuers
audience = [] # accepted "aud" values; empty skips the audience check
validation_mode = "scope" # "scope" (default) or "role"
role_mappings = "" # path to a role→scope YAML file, used when validation_mode = "role"

Obtain a token from the IDP as usual (client credentials, authorization code, …) and send it as a Bearer token. The Platform API never issues tokens in this mode.

Mode: file (local users)​

The login endpoint authenticates a username/password against [[platform_api.auth.file.users]] and issues an RS256 JWT signed with auth.jwt.private_key_file. Suitable for initial or air-gapped setup — prefer an IDP in production.

[platform_api.auth]
mode = "file"

[platform_api.auth.file.organization]
id = "default"
display_name = "Default"
uuid = "99089a17-72e0-4dd8-a2f4-c8dfbb085295" # emitted as the `organization` claim

[[platform_api.auth.file.users]]
username = "admin"
password_hash = "$2a$12$..." # bcrypt; htpasswd -bnBC 12 "" <password> | tr -d ':\n'
scopes = "ap:organization:manage ap:rest_api:manage ap:gateway:manage"

[platform_api.auth.jwt]
issuer = "platform-api"
public_key_file = "/etc/platform-api/keys/jwt_public.pem"
private_key_file = "/etc/platform-api/keys/jwt_private.pem"
token_ttl = "1h"

The user's scopes string becomes the scope claim of the issued token — trim it to restrict what that user can do.

Obtaining a token​

POST /api/portal/v0.9/auth/login (form-encoded; this path bypasses the auth middleware):

curl -X POST https://localhost:9243/api/portal/v0.9/auth/login \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=admin' \
-d 'password=<password>'

200 Response

{
"token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_at": 1767225600
}

Use token as the Bearer credential on every subsequent call. Its lifetime is auth.jwt.token_ttl.

Mode: external_token​

Tokens are minted by a trusted external issuer and only verified here, using auth.jwt.public_key_file. The Platform API does not sign anything in this mode, and private_key_file is not required. Token expiry is whatever exp the issuer set.

Required Claims​

ClaimRequiredPurpose
organizationYesUUID of the caller's organization. Every operation is scoped to it. A token without it is rejected.
scopeYes (in scope validation mode)Space-separated list of granted scopes, checked against the operation's declared scopes.
issYesMust match the configured issuer (auth.jwt.issuer, or one of auth.idp.issuer).
expYesExpired tokens are rejected.
subYesThe user's unique ID.
audConditionalEnforced in IDP mode when auth.idp.audience is non-empty.
org_name, org_handle, username, emailNoIdentity metadata surfaced to handlers.

Claim name mappings​

Claim names are configurable, so the same mapping is used for both issuing and validating tokens and the two can never drift apart. Each value is either a flat claim name (org_id) or a dot-separated path into a nested claim (realm_access.roles) — useful for IDPs like Keycloak.

[platform_api.auth.claim_mappings]
organization = "organization" # claim carrying the org ID
org_name = "org_name"
org_handle = "org_handle"
user_id = "sub"
username = "username"
email = "email"
scope = "scope" # space-separated scope string
roles = "" # e.g. "realm_access.roles" (Keycloak) or "roles" (Asgardeo)

Authorization​

Scope naming convention​

Scopes follow ap:<resource>[:<subresource>]:<action>:

FormGrants
ap:rest_api:readA single action on a resource
ap:rest_api:manageEvery action on that resource (read, create, update, delete)
ap:rest_api:deployment:manageEvery action on the subresource only — not on the parent rest_api

An operation may declare several acceptable scopes. The token needs at least one of them — which is why ap:rest_api:create and ap:rest_api:manage typically both appear on a create operation.

Validation modes​

auth.idp.validation_mode selects how effective scopes are derived:

  • scope (default) — the token's scope claim is used directly.
  • role — the roles found at claim_mappings.roles are expanded into scopes via the YAML file at auth.idp.role_mappings. When a token carries several roles, the effective scopes are the union of all matching role entries (most permissive wins).
# role_mappings YAML — requires a server restart to take effect
roles:
- name: platform-admin
scopes:
- ap:organization:manage
- ap:rest_api:manage
- ap:gateway:manage
- name: platform-operator
scopes:
- ap:organization:read
- ap:rest_api:read

Disabling scope checks​

[platform_api.auth]
scope_validation = false

This authenticates callers but performs no authorization checks. Use it only to temporarily bypass authorization during development — never in a deployed environment.

Unauthenticated paths​

[platform_api.auth] skip_paths lists path prefixes that bypass the auth middleware entirely — health and metrics probes, the file-mode login endpoint, and the internal gateway routes (which authenticate with a gateway token instead). Setting this key replaces the built-in default list, so keep any entries you still need.

Error Responses​

Authentication and authorization failures are deliberately uniform — the response never reveals why a credential was rejected. The specific reason is logged internally with a tracking ID.

StatusMeaningCause
401UnauthorizedMissing Authorization header, non-Bearer header, malformed/expired/invalid-signature token, wrong issuer, or missing organization claim
403ForbiddenToken is valid, but its effective scopes do not satisfy the operation's required scopes

A 401 carries the identical payload for every one of those causes, so it cannot be used to probe which part of a credential was wrong.

Troubleshooting​

  • Every request returns 401 after switching to IDP mode — check that jwks_url is reachable from the Platform API and that the token's iss is listed in auth.idp.issuer.
  • 401 with a token that the IDP says is valid — the organization claim is probably missing or under a different name. Point claim_mappings.organization at the claim your IDP actually emits.
  • 401 only for some clients in IDP mode — auth.idp.audience is non-empty and those tokens were minted for a different client. Add the audience value or leave the list empty to skip the check.
  • 403 on operations the user should be able to perform — compare the token's scope claim against the scopes listed on that operation's page. In role mode, confirm the role name in the token matches an entry in the role_mappings file (it requires a restart after editing).
  • 403 in role mode on every operation — claim_mappings.roles is unset, so no roles are read from the token. Set it to the claim path your IDP uses (realm_access.roles for Keycloak, roles for Asgardeo/Entra ID).
  • Login endpoint returns 401 in file mode — the stored password_hash must be a bcrypt hash; a plaintext password there will never match.

Scope Reference​

The complete set of scopes defined by this API, as declared in the OpenAPI OAuth2Security scheme.

  • OAuth2, flow: clientCredentials
  • Token URL declared in the spec: https://localhost:9243/oauth2/token

The declared token URL describes the clientCredentials flow an external IDP is expected to expose, and is what generated clients target in idp mode — the Platform API does not serve it itself. In file mode there is no client-credentials endpoint; obtain a token from the username/password login endpoint described under Obtaining a token (POST /api/portal/v0.9/auth/login) instead.

ScopeScope Description
ap:api_key:readRead API keys owned by the current user
ap:application:api_key:createCreate an application API key
ap:application:api_key:deleteDelete an application API key
ap:application:api_key:manageFull access to application API keys
ap:application:api_key:readRead application API keys
ap:application:association:api_key:readRead API keys for an application association
ap:application:association:createCreate an application association
ap:application:association:deleteDelete an application association
ap:application:association:manageFull access to application associations
ap:application:association:readRead application associations
ap:application:createCreate an application
ap:application:deleteDelete an application
ap:application:manageFull access to applications
ap:application:readRead applications
ap:application:updateUpdate an application
ap:gateway:createCreate a gateway
ap:gateway:deleteDelete a gateway
ap:gateway:manageFull access to gateways
ap:gateway:manifest:readRead a gateway manifest
ap:gateway:readRead gateways
ap:gateway_custom_policy:createCreate a gateway custom policy
ap:gateway_custom_policy:deleteDelete a gateway custom policy
ap:gateway_custom_policy:manageFull access to gateway custom policies
ap:gateway_custom_policy:readRead gateway custom policies
ap:gateway:token:createCreate a gateway token
ap:gateway:token:deleteDelete a gateway token
ap:gateway:token:manageFull access to gateway tokens
ap:gateway:token:readRead gateway tokens
ap:gateway:updateUpdate a gateway
ap:llm_provider:api_key:createCreate an LLM provider API key
ap:llm_provider:api_key:deleteDelete an LLM provider API key
ap:llm_provider:api_key:manageFull access to LLM provider API keys
ap:llm_provider:api_key:readRead LLM provider API keys
ap:llm_provider:createCreate an LLM provider
ap:llm_provider:deleteDelete an LLM provider
ap:llm_provider:deployment:createDeploy an LLM provider
ap:llm_provider:deployment:deleteDelete an LLM provider deployment
ap:llm_provider:deployment:manageFull access to LLM provider deployments
ap:llm_provider:deployment:readRead LLM provider deployments
ap:llm_provider:deployment:restoreRestore an LLM provider deployment
ap:llm_provider:deployment:undeployUndeploy an LLM provider deployment
ap:llm_provider:manageFull access to LLM providers
ap:llm_provider:readRead LLM providers
ap:llm_provider:updateUpdate an LLM provider
ap:llm_proxy:api_key:createCreate an LLM proxy API key
ap:llm_proxy:api_key:deleteDelete an LLM proxy API key
ap:llm_proxy:api_key:manageFull access to LLM proxy API keys
ap:llm_proxy:api_key:readRead LLM proxy API keys
ap:llm_proxy:createCreate an LLM proxy
ap:llm_proxy:deleteDelete an LLM proxy
ap:llm_proxy:deployment:createDeploy an LLM proxy
ap:llm_proxy:deployment:deleteDelete an LLM proxy deployment
ap:llm_proxy:deployment:manageFull access to LLM proxy deployments
ap:llm_proxy:deployment:readRead LLM proxy deployments
ap:llm_proxy:deployment:restoreRestore an LLM proxy deployment
ap:llm_proxy:deployment:undeployUndeploy an LLM proxy deployment
ap:llm_proxy:manageFull access to LLM proxies
ap:llm_proxy:readRead LLM proxies
ap:llm_proxy:updateUpdate an LLM proxy
ap:llm_template:createCreate an LLM provider template
ap:llm_template:deleteDelete an LLM provider template
ap:llm_template:manageFull access to LLM provider templates
ap:llm_template:readRead LLM provider templates
ap:llm_template:updateUpdate an LLM provider template
ap:mcp_proxy:createCreate an MCP proxy
ap:mcp_proxy:deleteDelete an MCP proxy
ap:mcp_proxy:deployment:createDeploy an MCP proxy
ap:mcp_proxy:deployment:deleteDelete an MCP proxy deployment
ap:mcp_proxy:deployment:manageFull access to MCP proxy deployments
ap:mcp_proxy:deployment:readRead MCP proxy deployments
ap:mcp_proxy:deployment:restoreRestore an MCP proxy deployment
ap:mcp_proxy:deployment:undeployUndeploy an MCP proxy deployment
ap:mcp_proxy:manageFull access to MCP proxies
ap:mcp_proxy:readRead MCP proxies
ap:mcp_proxy:updateUpdate an MCP proxy
ap:organization:createCreate an organization
ap:organization:manageFull access to an organization
ap:organization:readRead an organization
ap:project:createCreate a project
ap:project:deleteDelete a project
ap:project:manageFull access to projects
ap:project:readRead projects
ap:project:updateUpdate a project
ap:rest_api:api_key:createCreate an API key for a REST API
ap:rest_api:api_key:deleteDelete an API key of a REST API
ap:rest_api:api_key:manageFull access to a REST API's API keys
ap:rest_api:api_key:updateUpdate an API key of a REST API
ap:rest_api:createCreate a REST API
ap:rest_api:deleteDelete a REST API
ap:rest_api:deployment:createDeploy a REST API
ap:rest_api:deployment:deleteDelete a REST API deployment
ap:rest_api:deployment:manageFull access to REST API deployments
ap:rest_api:deployment:readRead REST API deployments
ap:rest_api:deployment:restoreRestore a REST API deployment
ap:rest_api:deployment:undeployUndeploy a REST API deployment
ap:rest_api:gateway:createAdd gateways to a REST API
ap:rest_api:gateway:manageFull access to a REST API's gateways
ap:rest_api:gateway:readRead a REST API's gateways
ap:rest_api:manageFull access to REST APIs
ap:rest_api:readRead REST APIs
ap:rest_api:updateUpdate a REST API
ap:secret:createCreate a secret
ap:secret:deleteDelete a secret
ap:secret:manageFull access to secrets
ap:secret:readRead secrets
ap:secret:updateUpdate a secret
ap:subscription:createCreate a subscription
ap:subscription:deleteDelete a subscription
ap:subscription:manageFull access to subscriptions
ap:subscription:readRead subscriptions
ap:subscription:updateUpdate a subscription
ap:subscription_plan:createCreate a subscription plan
ap:subscription_plan:deleteDelete a subscription plan
ap:subscription_plan:manageFull access to subscription plans
ap:subscription_plan:readRead subscription plans
ap:subscription_plan:updateUpdate a subscription plan

Was this page helpful?