Get started with the Alter SDK for TypeScript to make authenticated API calls to any OAuth provider, manage connections, and create connect sessions. The SDK supports OAuth tokens, API keys, and custom credentials, all retrieved and injected automatically.Documentation Index
Fetch the complete documentation index at: https://docs.alterauth.com/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Requires Node.js 20 or higher. TypeScript 5.0+ recommended.- npm
- pnpm
- yarn
Basic Setup
Key Principle: Zero Token Exposure — You never see or handle OAuth tokens. The SDK retrieves them from Alter Vault and injects them automatically. All SDK-to-backend communication is cryptographically secured for integrity, authenticity, and replay protection.
Configuration
CallerType.SERVICE for backend infrastructure callers that should not appear in the Developer Portal Agents tab.
Audit logging is always enabled and cannot be disabled — every API call is automatically logged for compliance. The SDK automatically includes the HTTP method and target URL in the audit trail for each token request.
Connecting an Identity Provider
If the application uses an external IDP (Okta, Entra ID, Auth0, Clerk, Keycloak, or any OIDC issuer), wire it up to the SDK so every request is scoped to the signed-in end user. This is required forprovider lookups (identity-based grant resolution) and powers group-based policies and instant deprovisioning.
One-time setup (Developer Portal): add the IDP to the application on its Identity page — paste the OIDC issuer URL, click Discover, then save. Alter Vault auto-detects the IDP type and claim mappings.
Single-IDP rule: each application can have only one active identity provider configuration at a time. To switch providers, remove the current IDP and add the replacement, then update JWT issuer settings and webhook/OIDC credentials for the replacement.
userTokenGetter that returns the end user’s IDP-issued JWT. The SDK attaches it to every token request so the backend can resolve the user from the JWT claims.
Two resolution modes — pass
grantId when the caller already knows the exact grant, or pass provider with an active end-user token source so the backend can resolve the grant from the JWT’s sub claim. The token source can come from constructor userTokenGetter or from a token cached via vault.authenticate().vault.authenticate() to open a browser-based OIDC login through the IDP and receive the user profile. The SDK caches the resulting token internally and installs it as the active token getter for that AlterVault instance (overriding any constructor-supplied userTokenGetter) — configure the IDP’s wallet/SDK client credentials in the Developer Portal first.
Quick Error Handling
Revoking a Grant
Permanently revoke a grant when it’s no longer needed. Tokens are deleted from Vault and the grant status is set torevoked. The user must re-authorize via Alter Connect to restore access.
revokeGrant() throws GrantNotFoundError if the grant does not exist or is already revoked.
When the AlterVault instance has userTokenGetter configured, revokeGrant() targets a grant owned by the authenticated caller — passing a grantId that belongs to someone else throws GrantNotFoundError. See Scoping grant operations to the authenticated user in the overview.
Provisioning Managed-Secret Grants
createManagedSecretGrant() ties a managed secret to a specific principal (user, IDP group, or system). Use it when an admin or backend job needs to provision access without sending the end user through Alter Connect.
Principal is a discriminated union (type field is the discriminator). label is required on UserPrincipal and GroupPrincipal (rendered in the wallet) and optional on SystemPrincipal. The backend resolves and persists the principal: UserPrincipal validates the JWT and binds the grant to the resolved app user; GroupPrincipal upserts the IDP group; SystemPrincipal records a headless grant — anyone with the grant id and a valid signature for the app can retrieve the credential, so use only for backend flows with no caller user.
Next Steps
SDK Overview
Core concepts, complete examples, actor tracking, and error handling
Quickstart Guide
Full integration walkthrough with frontend + backend
Python SDK
Python SDK equivalent