Oauth Login

Setup OAuth authentication by providing a complete GitHub OAuth integration with automatic user identity management. Handles the entire OAuth flow from configuration to user session management, eliminating the need to build authentication from scratch.

Key Benefits

  • Complete OAuth Flow: Handles authentication, callback processing, and user session management automatically
  • User Identity Linking: Automatically creates and links OAuth identities to existing users by email
  • Production Ready: Includes comprehensive test coverage, database migrations, and error handling
  • Extensible Design: Built on Ueberauth foundation, easily extended to support additional OAuth providers

Implementation Details The feature integrates Ueberauth with GitHub strategy, creating a complete user identity system. It generates a UserIdentity schema that links OAuth accounts to your existing user system, with automatic user creation or linking based on email matching. The implementation includes a dedicated controller for OAuth callbacks, proper error handling for edge cases, and LiveView integration for seamless user experience.

Usage Example

# Users can authenticate via OAuth or traditional methods
# OAuth users are automatically linked to existing accounts by email
# Access user's OAuth data through the user_identities association
user = Users.get_user_with_identities(user_id)
github_identity = Enum.find(user.user_identities, &(&1.provider == "github"))

Configuration Requires GitHub OAuth app credentials in environment variables (GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET). The feature automatically configures Ueberauth with GitHub strategy and adds the necessary routes to your router. Database migration creates the user_identities table with proper foreign key constraints.