Skip to content

API Key Storage

Not every integration uses OAuth. Many APIs authenticate with static API keys or webhook secrets. Authpipe stores these with the same encryption and retrieval model as OAuth tokens.

Use storeCredential to save an API key or webhook secret. This creates a connection with credential_type set to "api_key" or "webhook_secret".

const result = await authpipe.storeCredential({
provider: "sendgrid",
tenantId: "org_acme",
credentialType: "api_key",
credential: "SG.xxxx.yyyy",
});
console.log(result.connection_id); // "conn_..."
console.log(result.status); // "active"
ParameterRequiredDescription
providerYesProvider slug
tenant_idYesTenant that owns this credential
credential_typeYes"api_key" or "webhook_secret"
credentialYesThe secret value to store
user_idNoFor user-attached credentials
installation_idNoLink to an existing installation

Use the same getCredential call as OAuth tokens. The response includes credential_type so you know what you’re getting.

const { credential, credential_type } = await authpipe.getCredential({
provider: "sendgrid",
tenantId: "org_acme",
});
// credential_type === "api_key"
// credential === "SG.xxxx.yyyy"

To rotate an API key, call storeCredential again with the same provider and tenant. Authpipe upserts the connection with the new value and emits a credential.rotated event.

await authpipe.storeCredential({
provider: "sendgrid",
tenantId: "org_acme",
credentialType: "api_key",
credential: "SG.new-key.zzzz",
});

Webhook secrets from providers (e.g., Stripe’s whsec_...) are stored the same way:

await authpipe.storeCredential({
provider: "stripe",
tenantId: "org_acme",
credentialType: "webhook_secret",
credential: "whsec_abc123",
});

Retrieve it when you need to verify inbound webhooks:

const { credential } = await authpipe.getCredential({
provider: "stripe",
tenantId: "org_acme",
});

You still need a provider config for the provider, even for API key storage. Create one with auth_api_key support and set attachment to control tenant vs. user scoping.