This is a Django web application that implements GitHub OAuth authentication, allowing users to log in to the application using their GitHub credentials. The project demonstrates a clean, secure way of integrating social authentication into a Django web application.
- GitHub OAuth 2.0 Authentication
- Secure login process
- User profile page
- Environment variable management
- Simple and clean UI
- Python 3.8+
- pip
- GitHub Account
- GitHub OAuth Application
git clone https://github.com/jko8y/github-oauth-django.git
cd github-oauth-django# On macOS/Linux
python3 -m venv venv
source venv/bin/activate
# On Windows
python -m venv venv
venv\Scripts\activatepip install -r requirements.txt- Go to GitHub Developer Settings
- Click "New OAuth App"
- Fill in the details:
- Homepage URL:
http://localhost:8000 - Authorization callback URL:
http://localhost:8000/social-auth/complete/github/
- Homepage URL:
- Generate a Client ID and Client Secret
Create a .env file in the project root with the following content:
DJANGO_SECRET_KEY=your_django_secret_key
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
Note: Generate a secure Django secret key using Python:
from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())python manage.py migratepython manage.py runserverVisit http://localhost:8000 in your browser.
github_oauth_project/
│
├── github_oauth_project/
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
│
├── accounts/
│ ├── views.py
│ ├── urls.py
│ └── templates/
│ └── accounts/
│ ├── login.html
│ └── profile.html
│
├── .env
└── requirements.txt
- User clicks "Login with GitHub"
- Redirected to GitHub OAuth page
- User grants permissions
- GitHub sends authorization code
- Application exchanges code for access token
- User is logged in and redirected to profile
- Never commit
.envfile to version control - Use strong, unique secret keys
- Keep GitHub OAuth credentials confidential
- Use HTTPS in production
- Modify
accounts/views.pyto add custom logic - Customize templates in
accounts/templates/ - Extend user model if needed
- Ensure all dependencies are installed
- Check GitHub OAuth app settings
- Verify environment variables
- Clear browser cache if login issues persist
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
JK - Lets connect on 𝕏