A Python package for OAuth authentication with various social providers.
Project description
A Python package for OAuth authentication with various social providers, inspired by Laravel Socialite.
Installation
pip install py-socialite
Configuration
Create a configuration file (e.g., config.py) with your OAuth credentials:
# config.py
SOCIAL_PROVIDERS = {
'google': {
'client_id': 'your-client-id',
'client_secret': 'your-client-secret',
'redirect_uri': 'your-callback-url'
},
'github': {
'client_id': 'your-client-id',
'client_secret': 'your-client-secret',
'redirect_uri': 'your-callback-url'
},
'dropbox': {
'client_id': 'your-client-id',
'client_secret': 'your-client-secret',
'redirect_uri': 'your-callback-url'
},
'x': {
'client_id': 'your-client-id',
'client_secret': 'your-client-secret',
'redirect_uri': 'your-callback-url'
}
}
Set the configuration path in your environment:
export SOCIALITE_CONFIG_PATH=/path/to/config.py
Usage
from py_socialite.socialite import Socialite
# Initialize Socialite
socialite = Socialite()
# Get authorization URL
auth_url = socialite.provider('google').get_auth_url()
# After callback, get user info
user = socialite.provider('google').get_user(code)
Error Handling
The package raises SocialAuthError for any authentication issues.
try:
user = socialite.provider('google').get_user(code)
except SocialAuthError as e:
print(f"Authentication failed: {str(e)}")
Project Structure
py-socialite/
├── py_socialite/
│ ├── __init__.py # Version and package info
│ ├── exceptions.py # Custom exceptions
│ ├── config.py # Provider configurations
│ ├── socialite.py # Main service class
│ └── providers/
│ ├── base.py # Abstract base provider
│ └── google.py # Google implementation
├── setup.py # Package setup
└── deploy.sh # Deployment script
Requirements
- python 3.10+
- requests
- python-dotenv
support providers
- github
- dropbox
- x
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters