Authentication
The ERPBridge SDK supports consume-only bearer authentication for ERPBridge
v0.3.0-alpha.1 and later. An ERPBridge administrator provisions the opaque
token. The ERPBridge SDK sends the token but never creates, lists, reveals,
revokes, refreshes, or stores tokens.
Configurationโ
Set an explicit token or an environment-variable name. The ERPBridge SDK
resolves the credential once when createClient runs:
import { createClient } from '@erpbridge/sdk'
const client = createClient({
baseUrl: 'https://bridge.example.com',
tokenEnv: 'ERPBRIDGE_TOKEN',
auth: {
metrics: { tokenEnv: 'ERPBRIDGE_METRICS_TOKEN' },
logs: { tokenEnv: 'ERPBRIDGE_LOGS_TOKEN' },
},
})
The default environment variable is ERPBRIDGE_TOKEN. The legacy
ERPBridge_TOKEN name is checked only when the canonical variable is absent,
so existing deployments continue to work while they migrate.
For each MCP, metrics, or logs request, the ERPBridge SDK uses this precedence:
- surface
token; - surface
tokenEnvvalue; - global
token; - global
tokenEnvvalue, defaulting toERPBRIDGE_TOKEN, then the legacyERPBridge_TOKENvalue when the canonical variable is absent; - anonymous access.
The ERPBridge SDK treats an empty token as absent. A browser bundle cannot read a Node environment automatically. Provide a token explicitly when the server requires authentication. Do not put a long-lived token in a public browser bundle unless the deployment design makes that safe.
The ERPBridge SDK also uses the global credential for health, cache, registry, and direct invoke requests. It does not locally assert that this credential has the server's admin permission.
Server scopesโ
When server authentication is enabled, the protected surface scopes are:
| SDK surface | Server scope |
|---|---|
client.mcp and client.tools | mcp |
client.metrics | metrics |
client.logs | logs |
Declare expected scopes for local fail-fast checks:
const client = createClient({
tokenEnv: 'ERPBRIDGE_TOKEN',
declaredScopes: ['mcp'],
})
declaredScopes is an application assertion, not token introspection. If you
omit it, the ERPBridge SDK sends the request and lets the server decide. It
never infers permissions from an opaque token.
If a non-empty declaration excludes the requested surface, the ERPBridge SDK
throws AuthorizationError before it makes a network request. This local
check only detects configuration errors. The server remains the authority.
Errorsโ
AuthenticationErrorrepresents HTTP 401: the server did not accept the credential. Its optionalwwwAuthenticatefield is the server challenge; Applications must not log its value.AuthorizationErrorrepresents HTTP 403: the credential is not authorized for the request. Its optionalrequiredScopeis present only when the server explicitly supplies one.
The ERPBridge SDK does not implement OAuth, PKCE, token refresh, or token
lifecycle operations. Use bridgectl or the server administrator workflow to
manage tokens.