Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add programmatic configuration API #43

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

nicknisi
Copy link
Contributor

@nicknisi nicknisi commented Mar 6, 2025

Problem

Currently, users must provide secrets and configuration values through environment variables (process.env). This has several limitations:

  • Security concerns with secrets in environment variables
  • Doesn't work well across different JavaScript runtimes (Deno, Cloudflare Workers, etc.)
  • No convenient way to integrate with secret management systems

Solution

This PR adds a new configure() function that enables programmatic configuration with multiple flexible patterns:

// in entry.server.tsx

// Direct values approach
configure({
  clientId: 'client_...',
  apiKey: 'sk_test_...',
  redirectUri: 'http://localhost:3000/callback',
  cookiePassword: 'secure-password...',
});

// Function-based for different environments (may not yet be fully supported)
configure(key => Deno.env.get(key));

// Hybrid approach
configure({ redirectUri: 'https://example.com/callback' }, mySecretSource);

Implementation Details

  • Added lazy initialization to prevent eager loading of credentials
  • Environment variables still take precedence (maintains backward compatibility)
  • Centralized default values for optional settings
  • Added TypeScript overloads for improved developer experience
  • Documentation in README updated to explain the new configuration options

Benefits

  • Improved security - credentials don't need to be exposed in environment variables
  • Cross-platform support - works in any JavaScript runtime
  • Better developer experience - flexible API with strong typing
  • Secret management integration - values can be loaded from vault services

Testing

  • Added unit tests for all configuration patterns
  • Verified backward compatibility with environment variables

Additional Changes

  • Lazily instantiates workos instance (parity with authkit-nextjs)
  • exposes getWorkOS() function to user to get access to WorkOS instance (parity with authkit-nextjs)

Breaking Changes

None. This is a non-breaking enhancement that maintains compatibility with existing code.

Fixes #38

@nicknisi nicknisi marked this pull request as ready for review March 6, 2025 14:44
@nicknisi nicknisi requested review from chantastic and mthadley March 6, 2025 14:44
@nicknisi nicknisi force-pushed the nicknisi/config-object branch from 87e970f to 07056f4 Compare March 6, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Security: Allow alternative methods of setting sensitive values
1 participant