-
-
Notifications
You must be signed in to change notification settings - Fork 0
Installation Guide
This guide covers advanced installation options for TokenAuthority.
Add TokenAuthority to your Gemfile:
gem "token_authority"Run bundle install:
$ bundleRun the install generator:
$ bin/rails generate token_authority:installRun the migration:
$ bin/rails db:migrateThe generator accepts the following options:
| Option | Default | Description |
|---|---|---|
--user_table_name |
users |
Name of your application's user table |
--user_foreign_key_type |
bigint |
Primary key type of your user table (bigint, uuid, integer) |
If your user table is named something other than users:
$ bin/rails generate token_authority:install --user_table_name=accountsIf your user table uses UUID primary keys:
$ bin/rails generate token_authority:install --user_foreign_key_type=uuidYou can combine options:
$ bin/rails generate token_authority:install --user_table_name=accounts --user_foreign_key_type=uuidThe generator creates three things:
A migration file that creates the required database tables (see Database Tables below).
An initializer at config/initializers/token_authority.rb with default configuration. See the Configuration Reference for all available options.
Customizable views at app/views/token_authority/. See Customizing Views for details.
The migration creates the following tables:
| Table | Purpose |
|---|---|
token_authority_clients |
OAuth client applications (stores client credentials and settings) |
token_authority_authorization_grants |
Authorization codes issued during the OAuth flow |
token_authority_challenges |
PKCE code challenges for enhanced security |
token_authority_sessions |
Tracks issued tokens and their status (created, expired, refreshed, revoked) |
token_authority_jwks_caches |
Cached JWKS documents for private_key_jwt authentication |
token_authority_client_metadata_document_caches |
Cached client metadata documents for URL-based client identifiers |
All tables use the token_authority_ prefix to avoid conflicts with your application's tables.
If you're using subdomain constraints for multiple protected resources, you'll need additional configuration for local development.
Rails subdomain constraints (e.g., constraints subdomain: "mcp") require a domain that properly resolves subdomains. localhost doesn't support subdomains out of the box.
The lvh.me domain resolves to 127.0.0.1 and supports subdomains, making it ideal for development:
-
http://lvh.me:3000→ your main app -
http://mcp.lvh.me:3000→ MCP subdomain -
http://api.lvh.me:3000→ API subdomain
Add lvh.me to your allowed hosts in config/environments/development.rb:
config.hosts << /.*\.lvh\.me/Update your environment variables to use lvh.me:
TOKEN_AUTHORITY_BASE_URL=http://lvh.me:3000
TOKEN_AUTHORITY_MCP_URL=http://mcp.lvh.me:3000/Note: Some OAuth clients may append a trailing slash to resource URLs. Include the trailing slash in your
TOKEN_AUTHORITY_MCP_URLto ensure exact matches during authorization validation.
Rails.application.routes.draw do
token_authority_auth_server_routes
constraints subdomain: "mcp" do
token_authority_protected_resource_route
post "/", to: "model_context_protocol#index"
end
endWith this configuration:
- Authorization server metadata:
http://lvh.me:3000/.well-known/oauth-authorization-server - Protected resource metadata:
http://mcp.lvh.me:3000/.well-known/oauth-protected-resource - MCP endpoint:
http://mcp.lvh.me:3000/
After installation:
- Configure TokenAuthority for your environment
- Set up user authentication integration
- Mount the engine routes in your application
Getting Started
- Installation Guide
- MCP Quickstart
- Configuration Reference
- User Authentication
- Protecting API Endpoints
- Customizing Views
- Event Logging
- Instrumentation
Process Flows
- Authorization Code Grant
- Authorization Code Redemption
- Token Refresh
- Token Revocation
- Authorization Server Metadata
- Protected Resource Metadata
- Dynamic Client Registration
- Client Metadata Documents
Development