Skip to main content

@happyvertical/auth

Unified authentication interface supporting multiple providers.

Providers

  • Keycloak - Full OIDC/OAuth2 with admin capabilities
  • AWS Cognito - OAuth2 with hosted UI
  • Nostr - Decentralized public key identity

Installation

npm install @happyvertical/auth

Claude Code Context

Install Claude Code context files for AI-assisted development:

npx have-auth-context

This copies the package's AGENT.md documentation and metadata.json metadata to your project's .claude/ directory, enabling Claude to provide better assistance when working with this package.

Quick Start

import { getAuth } from '@happyvertical/auth';

// Keycloak
const auth = await getAuth({
type: 'keycloak',
serverUrl: 'https://auth.example.com',
realm: 'my-realm',
clientId: 'my-app'
});

// Cognito
const auth = await getAuth({
type: 'cognito',
region: 'us-east-1',
userPoolId: 'us-east-1_xxx',
clientId: 'xxx'
});

// Nostr
const auth = await getAuth({
type: 'nostr',
relays: ['wss://relay.damus.io']
});

// Authenticate
const result = await auth.authenticate({ username, password });
console.log(result.accessToken);

// Validate token
const claims = await auth.validateToken(token);

// Check role
if (await auth.hasRole(token, 'admin')) {
// Admin access
}

Documentation

See AGENT.md for complete API documentation.

License

MIT