As a user, I want to log in to the WebAPI application using my social accounts (e.g., Google, GitHub), so that I can access the platform more easily without the need to create a separate account.
Description:
This feature introduces OAuth2-based login for users via popular social platforms like Google or GitHub. The user will have the option to either register and log in with an email and password (using JWT) or authenticate via OAuth. This will improve the user experience by providing an alternative, streamlined login flow.
User Flow:
Select Social Login Provider:
On the login page, the user can select "Login with Google", "Login with GitHub", or other available providers.
OAuth Provider Authorization:
The user will be redirected to the selected OAuth provider’s login page (e.g., Google).
After successful login, the OAuth provider will redirect back to the application with an authorization code or access token.
Backend OAuth Handling:
The backend receives the authorization code/token, exchanges it for user data, and creates or updates the user profile in the database.
If the user logs in for the first time, a new user account is created and associated with the provider. For returning users, the profile is updated.
JWT Token Assignment:
After OAuth authentication, the backend issues a JWT token to the user for further API interactions.
Celery Tasks for Welcome Emails:
After a successful login or registration, a welcome email is sent asynchronously using Celery.
Acceptance Criteria:
OAuth Providers: Users can log in using Google and GitHub.
JWT Token Integration: After successful OAuth authentication, a JWT token is issued for the user session.
User Creation/Update:
If the user logs in for the first time, a new profile is created.
If the user already exists, the profile is updated with the latest OAuth data.
Error Handling: If OAuth authentication fails, a descriptive error message is returned to the frontend.
Welcome Email: A Celery task sends a welcome email to the user after registration or login.
Security: Ensure OAuth tokens are validated securely, and only trusted providers are used.
Technical Implementation Notes:
Dependencies:
Use django-allauth or authlib for OAuth2 integration.
Djoser for JWT token management.
Celery for background task handling (e.g., sending welcome emails).
Settings Configuration:
Update INSTALLED_APPS to include OAuth libraries (django-allauth or authlib).
Add OAuth provider credentials (e.g., Google Client ID/Secret) in environment variables.
Djoser and OAuth Integration:
Configure custom views to handle OAuth-based login and issue JWT tokens after successful OAuth authentication.
Backend OAuth Flow:
Exchange the authorization code from the provider with an access token.
Retrieve the user’s profile from the OAuth provider.
Create or update the user in the database.
Frontend Changes:
Add "Login with Google" and "Login with GitHub" buttons to the login page.
Handle OAuth redirection and display error messages if OAuth fails.
Example API Flow:
Frontend:
User clicks "Login with Google" -> Redirect to https://accounts.google.com/o/oauth2/auth.
Backend:
OAuth provider redirects back with authorization code ->
Exchange code for access token -> Retrieve user profile -> Create/Update user -> Issue JWT token.
Tasks:
Backend Setup:
Install and configure django-allauth or authlib.
Configure OAuth providers in Django settings.
JWT Integration:
Extend Djoser views to support OAuth-based authentication.
Frontend Integration:
Add social login buttons and handle OAuth redirection.
Testing:
Write unit and integration tests for OAuth login and JWT issuance.
Documentation:
Update project documentation with instructions for OAuth setup.
Title:
As a user, I want to log in to the WebAPI application using my social accounts (e.g., Google, GitHub), so that I can access the platform more easily without the need to create a separate account.
Description:
This feature introduces OAuth2-based login for users via popular social platforms like Google or GitHub. The user will have the option to either register and log in with an email and password (using JWT) or authenticate via OAuth. This will improve the user experience by providing an alternative, streamlined login flow.
User Flow:
Select Social Login Provider:
OAuth Provider Authorization:
Backend OAuth Handling:
JWT Token Assignment:
Celery Tasks for Welcome Emails:
Acceptance Criteria:
Technical Implementation Notes:
Dependencies:
django-allauth
orauthlib
for OAuth2 integration.Settings Configuration:
INSTALLED_APPS
to include OAuth libraries (django-allauth
orauthlib
).Djoser and OAuth Integration:
Backend OAuth Flow:
Frontend Changes:
Example API Flow:
Frontend:
User clicks "Login with Google" -> Redirect to
https://accounts.google.com/o/oauth2/auth
.Backend:
OAuth provider redirects back with authorization code ->
Exchange code for access token -> Retrieve user profile -> Create/Update user -> Issue JWT token.
Tasks:
Backend Setup:
JWT Integration:
Frontend Integration:
Testing:
Documentation: