Amphora Authentication Adapter

2.1.0 · active · verified Wed Apr 22

amphora-auth serves as an authentication adapter specifically designed for the Amphora content management system, providing robust user authentication capabilities within the Clay ecosystem. It facilitates both local username/password authentication and seamless integration with a variety of third-party OAuth providers, including Google, Twitter, Slack, Cognito, and LDAP. This broad support enables flexible and secure authentication strategies for applications built on the Clay platform. The current stable version is 2.1.0. While a specific release cadence isn't explicitly stated, updates likely align with developments in the broader Clay platform. Its primary differentiator is its deep, opinionated integration with Amphora and Clay, which significantly simplifies the setup and management of diverse authentication backends for Clay-based applications, streamlining security configuration.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `amphora-auth` within an Express application, showing the required parameters for basic setup and mocking dependencies like Redis store, site metadata, and storage. It highlights the primary configuration function of the module.

import amphoraAuth from 'amphora-auth';
import express from 'express';
import redis from 'redis';
import session from 'express-session';
import connectRedis from 'connect-redis';

const app = express();
const router = express.Router();
const RedisStore = connectRedis(session);

// Dummy implementations for required parameters
const providers = {
  google: {
    // In a real app, these would come from env vars
    consumerKey: process.env.GOOGLE_CONSUMER_KEY ?? '',
    consumerSecret: process.env.GOOGLE_CONSUMER_SECRET ?? ''
  }
  // ... other providers like twitter, slack, cognito, ldap
};

const redisClient = redis.createClient();
const store = new RedisStore({ client: redisClient });

const site = { slug: 'my-site', host: 'localhost:3001' }; // Example site metadata
const storage = { 
  get: () => Promise.resolve({ data: {} }),
  put: () => Promise.resolve({})
}; // Mock DB instance
const bus = { 
  publish: () => {},
  subscribe: () => {}
}; // Mock Redis bus instance

// Initialize auth module
amphoraAuth({
  router, // Site router for auth routes
  providers, // Authentication providers configuration
  store, // Redis Session Store for sessions
  site, // Site metadata
  storage, // DB instance for user storage
  bus // Redis bus instance for inter-process communication
});

app.use(session({
  store: store,
  secret: 'supersecretkey',
  resave: false,
  saveUninitialized: false,
  cookie: { secure: false } // Set to true in production with HTTPS
}));

app.use(router);

app.get('/', (req, res) => {
  res.send('Amphora Auth is running!');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

view raw JSON →