Authentication Overview
Gumroad uses multiple authentication mechanisms to support various access patterns:- Devise - Primary user authentication for web and API
- Doorkeeper - OAuth 2.0 provider for third-party integrations
- OmniAuth - Social login (Facebook, Google, Twitter, Apple)
- Pundit - Authorization and access control policies
Devise Configuration
Devise handles user authentication with several custom configurations.Setup
Devise is configured inconfig/initializers/devise.rb:
The authentication key is
:login which accepts either username or email, providing flexibility for users.Login Methods
Users can authenticate using:- Email/Username + Password
- Two-Factor Authentication (via
active_model_otp) - OAuth (Facebook, Google, Twitter, Apple)
Development Login
For local development, use these test credentials:OAuth with Doorkeeper
Doorkeeper provides OAuth 2.0 server functionality, allowing third-party applications to access Gumroad APIs on behalf of users.Configuration
Doorkeeper is configured inconfig/initializers/doorkeeper.rb:
OAuth Scopes
Doorkeeper defines granular scopes for API access:Available OAuth Scopes
Available OAuth Scopes
- view_public - Default scope, view public information
- edit_products - Create and modify products
- view_sales - View sales data
- view_payouts - View payout information
- mark_sales_as_shipped - Update shipping status
- refund_sales - Process refunds
- edit_sales - Modify sale records
- revenue_share - Access revenue share data
- ifttt - IFTTT integration scope
- mobile_api - Mobile app access
- creator_api - Creator API access
- view_profile - View user profile
- helper_api - Helper widget API
Grant Flows
Doorkeeper supports three OAuth 2.0 grant flows:1
Authorization Code
Standard OAuth flow for web applications. Users authorize access, and the app receives an authorization code to exchange for an access token.
2
Client Credentials
For server-to-server authentication without a specific user context.
3
Resource Owner Password
Direct authentication with username/password. Used for mobile apps and trusted clients.
Resource Owner Password Flow
The password grant supports multiple authentication methods:This flexible approach allows mobile apps to authenticate using social providers or traditional credentials through a single endpoint.
Social Authentication (OmniAuth)
Gumroad integrates with major social providers using OmniAuth:Supported Providers
- Facebook -
omniauth-facebook - Google -
omniauth-google-oauth2 - Twitter -
omniauth-twitter - Apple -
apple_idgem - Stripe Connect -
omniauth-stripe-connect
Configuration
OmniAuth providers are configured inconfig/initializers/omniauth.rb and referenced in Devise initializer:
CSRF Protection
Cross-site request forgery protection is enabled:Authorization with Pundit
Pundit provides object-oriented authorization through policy classes.Policy Structure
Policies are defined inapp/policies/ and follow this pattern:
Controller Integration
Policies are called in controllers:Policy Scopes
Scopes filter collections based on permissions:Security Best Practices
Password Security
Devise is configured with
devise-pwned_password to check passwords against known breaches.Rate Limiting
rack-attack provides rate limiting for authentication endpoints to prevent brute force attacks.Session Security
Sessions are stored in Redis with secure cookies. HTTPS is enforced in production via
rack-ssl.Two-Factor Auth
TOTP-based 2FA is available via
active_model_otp for enhanced account security.API Authentication
Access Token Usage
API requests use Bearer token authentication:Token Management
- Access tokens don’t expire by default (
access_token_expires_in nil) - Refresh tokens are enabled (
use_refresh_token) - Authorization codes expire after 10 minutes
Each OAuth application must have an owner (enabled with
enable_application_owner confirmation: true).Testing Authentication
RSpec Helpers
Devise provides test helpers for authentication:Testing OAuth
OAuth flows can be tested using VCR cassettes to record and replay API responses:Environment Variables
Required authentication configuration:Next Steps
Architecture
Learn about the overall system architecture
Testing
Write tests for authentication flows
API Reference
Explore the API documentation
Contributing
Contribute to authentication features