How it works
- The SDK obtains an OIDC token from the local cloud metadata endpoint (or a custom
tokenSource). - It exchanges the token at
POST /v1/auth/token-exchangefor a short-lived Nexus session token. - All subsequent HTTP requests use
Authorization: Bearer <session_token>instead ofX-Nexus-API-Key. - When the server sends an
auth_expiringSSE event, the SDK proactively refreshes the session token before it expires.
Enabling WIF
apiKey = null when using WIF. If both are set, the session token takes precedence once exchanged.
Security note (v0.9.0):
baseUrl must use https:// - NexusClient.create rejects plain-http endpoints (loopback/localhost excepted for development), since credentials travel on every request.Providers
kubernetes
Reads the service account token projected into every Kubernetes pod.
- Token path:
/var/run/secrets/kubernetes.io/serviceaccount/token - Setup: Mount the service account token (default in Kubernetes 1.21+). Configure a trust policy in Nexus with the cluster’s OIDC issuer URL.
aws
Reads the web identity token file used by IAM Roles for Service Accounts (IRSA) on EKS.
- Environment variable:
AWS_WEB_IDENTITY_TOKEN_FILEmust point to an existing token file.
aws_iam (v0.9.0)
For non-EKS AWS compute (ECS/Fargate, Lambda, plain EC2) that has IAM credentials but no OIDC token. The SDK SigV4-signs an STS GetCallerIdentity request with the standard AWS credential chain - never sending it to AWS - and posts the signed headers + body to /v1/auth/token-exchange. Nexus replays it against a pinned STS endpoint and matches the caller’s IAM role against an aws_iam trust policy (subject = arn:aws:iam::<account>:role/<name>). Requires the optional software.amazon.awssdk:auth + :regions dependencies; not auto-detected.
X-Nexus-Server-ID is your service’s own base-URL host, verified by the backend against the host the request arrived on - so a captured signed request is valid for that ONE service only.
gcp
Fetches a signed OIDC ID token from the GCP instance metadata endpoint.
- Metadata URL:
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience=<audience>
azure
Authenticates an Azure managed identity or AKS workload identity. On AKS with Azure Workload Identity the SDK prefers the projected federated token file ($AZURE_FEDERATED_TOKEN_FILE); otherwise it fetches a managed-identity token from the Azure IMDS.
- Federated file (preferred):
$AZURE_FEDERATED_TOKEN_FILE(AKS Workload Identity). - IMDS URL:
http://169.254.169.254/metadata/identity/oauth2/token
developer
Reads an OIDC token from the environment variable NEXUS_DEV_OIDC_TOKEN. Intended for local development and CI pipelines where a real cloud identity is not available.
auto (default)
Probes the environment and returns the first provider whose credential material is actually present (v0.9.0 - the token files are stat-ed and the metadata servers live-probed, ~1 s timeout; earlier versions keyed on environment-variable presence):
kubernetes(token file exists)aws(AWS_WEB_IDENTITY_TOKEN_FILEset and the file exists)azure(AZURE_FEDERATED_TOKEN_FILEset and the file exists)gcp(metadata server reachable)azureIMDS (metadata server reachable)developer(NEXUS_DEV_OIDC_TOKENset)
aws_iam is deliberately not in the auto-detect chain - select it explicitly.
Custom token source
For environments not covered by the built-in providers, supply an async lambda viatokenSource. When tokenSource is set, provider is ignored entirely.
null to signal that no token is available - the SDK will throw NexusWifNotConfiguredException.
Token exchange flow
At client creation, the SDK calls:session_token and sets sessionExpiry = now + expires_in - 60s (60-second safety margin). All subsequent requests use Authorization: Bearer <session_token>.
Project-level vs service-level trust policies
The Nexus backend supports trust policies at two scopes:
The SDK always connects to a specific service via its
baseUrl. The URL slug identifies the service - this works the same as API keys. At token exchange time, the backend checks service-level trust policies first, then falls back to project-level.
