OAuth2 integration made easy with our JavaScript SDK
npm install @zea.cl/thalamus-js
# or with yarn
yarn add @zea.cl/thalamus-js
📦 Package Information
TypeScript SDK for Thalamus OAuth2 - Published on npm as
@zea.cl/thalamus-js
Create a Thalamus client instance with your OAuth2 credentials:
import { ThalamusClient } from "@zea.cl/thalamus-js";
const thalamus = new ThalamusClient({
authUrl: "https://auth.zea.cl",
clientId: process.env.OAUTH2_CLIENT_ID,
clientSecret: process.env.OAUTH2_CLIENT_SECRET,
redirectUri: "https://myapp.com/auth/callback"
});
The SDK provides simple methods:
thalamus.auth.getAuthorizationUrl() - Generate login URL with PKCEthalamus.auth.exchangeCode() - Exchange authorization code for tokens
thalamus.auth.refreshToken() - Refresh expired access tokensthalamus.tokens.introspect() - Validate and inspect token metadatathalamus.tokens.revoke() - Revoke access or refresh tokensExample: Login Flow
// 1. Generate login URL and redirect user
const { url, state, codeVerifier } =
await thalamus.auth.getAuthorizationUrl();
// 2. After callback, exchange code for tokens
const tokens = await thalamus.auth.exchangeCode({
code: authorizationCode,
codeVerifier: codeVerifier
});
// 3. Validate token
const info = await thalamus.tokens.introspect(
tokens.access_token
);
For web apps with user login
For machine-to-machine (M2M)
Renew expired access tokens
The standard OAuth2 flow for web applications:
For backend services that need to authenticate without a user, use the
getClientCredentialsToken()
method
with desired scopes.
Use thalamus.tokens.introspect(token)
to validate tokens and retrieve metadata like user_id, scope, and expiration.
Complete Examples Available
examples/nextjs-app-router/examples/express-api/examples/direct-api/Our SDK includes PKCE (code_challenge) by default for enhanced security.
Use httpOnly cookies for web apps. Never expose tokens in localStorage or client-side code.
Always verify the state parameter matches to prevent CSRF attacks.
Never use OAuth2 over HTTP in production. Always require HTTPS.