This gem server now includes a web-based authentication system for gem owners to log in and manage their gems.
- Login/Register: Username and password authentication using OmniAuth Identity
- Dashboard: View all gems you own with their status (active/yanked)
- Session Management: Secure cookie-based sessions
- Password Security: Passwords are hashed using bcrypt
The authentication system requires additional database columns. Run the migration:
bundle exec rake db:migrateThis adds email and password_digest columns to the owners table.
You can create a test user using the provided script:
bundle exec ruby bin/create_test_userThis creates a user with:
- Email:
test@example.com - Password:
password123
bundle exec hanami serverNavigate to:
- Login: http://localhost:2300/auth/login
- Register: http://localhost:2300/auth/register
- Dashboard: http://localhost:2300/auth/dashboard (after login)
The following authentication routes are available:
GET /auth/login- Login pageGET /auth/register- Registration pagePOST /auth/identity/callback- OmniAuth callback (handles login)POST /auth/identity/register- OmniAuth registrationGET /auth/dashboard- User dashboard (requires authentication)GET /auth/logout- Logout
When logged in, the dashboard shows:
-
Statistics:
- Total gems owned
- Active gems count
- Yanked gems count
-
Gem List: All your gems with:
- Gem name (with scope path if applicable)
- Version number
- Status (Active/Yanked)
- Creation date
You can also create users directly via the database console:
require_relative "config/database"
require "bcrypt"
require "securerandom"
db = Them::Server::Database.db
db[:owners].insert(
name: "your-username",
email: "your-email@example.com",
password_digest: BCrypt::Password.create("your-password"),
api_key: SecureRandom.hex(32),
created_at: Time.now,
updated_at: Time.now
)- Passwords are hashed using bcrypt (cost factor 12)
- Sessions expire after 30 days of inactivity
- Session cookies use
SameSite: Laxfor CSRF protection - Set a strong
SESSION_SECRETenvironment variable in production
SESSION_SECRET- Secret key for session encryption (required in production)
Example:
export SESSION_SECRET=$(openssl rand -hex 64)The authentication system uses:
- OmniAuth - Authentication framework
- OmniAuth Identity - Username/password authentication strategy
- BCrypt - Password hashing
- Rack::Session::Cookie - Session management
- Sequel - Database ORM (Identity model uses Sequel adapter)
The Identity model extends Sequel::Model and uses the owners table, allowing gem owners to authenticate with email/password in addition to API keys.