Skip to content

Conversation

@AdaInTheLab
Copy link
Owner

Bearer Token Authentication for AI Agent Access

What & Why

This PR enables AI agents to authenticate with the API using Bearer tokens, allowing them to autonomously create Lab Notes. This is a foundational change that transforms AI from passive assistants into active co-researchers capable of documenting discoveries in real-time.

The implementation maintains full backward compatibility - browser OAuth continues to work exactly as before. We're adding a new authentication method, not replacing the existing one.

Changes

Core Authentication

Updated POST /admin/notes to use requireAuth(db) middleware instead of requireAdmin
Enhanced requireAuth to accept both session auth (browser OAuth) and Bearer tokens (CLI/AI agents)
Added ADMIN_DEV_BYPASS support for testing
Fixed import paths to use relative imports (../auth/tokens.js instead of bare module names)

Testing

✅ All 11 test suites passing
✅ All 41 tests passing
✅ Integration tested end-to-end with Bearer tokens
✅ Browser OAuth flow unchanged and working

Security

Raw tokens never stored (only SHA-256 hash)
Tokens prefixed by environment: hpl_test_ or hpl_live_
Configurable expiration
Instant revocation capability
Tracks created_by_user and last_used_at

Breaking Changes

None! This is purely additive. Existing browser authentication continues to work unchanged.
What's Next
This enables the CLI and frontend token creation UI (separate PRs) to complete the full AI co-researcher workflow.

Enable AI agents to authenticate and create Lab Notes via Bearer tokens.
Updated requireAuth middleware to accept both session (browser OAuth) and
Bearer tokens (CLI/AI agents). No breaking changes - browser auth unchanged.

Changes:
- adminRoutes: POST /admin/notes uses requireAuth(db) instead of requireAdmin
- requireAuth: supports session auth + Bearer token auth + dev bypass
- Fixed imports to use relative paths (../auth/tokens.js)
- All tests passing (11 suites, 41 tests)

This enables the first AI co-researcher to autonomously document discoveries.

Co-authored-by: Ada <ada@thehumanpatternlab.com>
Co-authored-by: Sage <sage@thehumanpatternlab.com>
Co-authored-by: Carmel <carmel@thehumanpatternlab.com>
@AdaInTheLab AdaInTheLab merged commit baf9e23 into main Jan 24, 2026
1 check passed
@AdaInTheLab AdaInTheLab deleted the feat/bearer-token branch January 24, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants