Skip to main content

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',
        'scope': 'openid email profile'
    },
    'github': {
        'client_id': 'your-client-id',
        'client_secret': 'your-client-secret',
        'redirect_uri': 'your-callback-url',
        'scope': 'read:user user:email'
    },
    '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',
        'scope': 'tweet.read users.read follows.read offline.access'
    },
    'linkedin': {
        'client_id': 'your-client-id',
        'client_secret': 'your-client-secret',
        'redirect_uri': 'your-callback-url',
        'scope': 'openid profile email'
    },
    'facebook': {
        'client_id': 'your-client-id',
        'client_secret': 'your-client-secret',
        'redirect_uri': 'your-callback-url',
        'scope': 'email public_profile'
    },
    'microsoft': {
        'client_id': 'your-client-id',
        'client_secret': 'your-client-secret',
        'redirect_uri': 'your-callback-url',
        'scope': 'openid email profile User.Read'
    }
}

Set the configuration path in your environment:

export SOCIALITE_CONFIG_PATH="modules.common.config.socialite"

# or add it to your .env file
SOCIALITE_CONFIG_PATH='modules.common.config.socialite'

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

  • google
  • github
  • dropbox
  • x
  • facebook
  • microsoft
  • linkedin

Response sample data

{
    "provider": "google",
    "id": "1234567890",
    "email": "example@example.com",
    "name": "John Doe",
    "avatar": "https://example.com/avatar.jpg",
    "raw": {
        .....
    }
}

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

py_socialite-0.0.4.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_socialite-0.0.4-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file py_socialite-0.0.4.tar.gz.

File metadata

  • Download URL: py_socialite-0.0.4.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for py_socialite-0.0.4.tar.gz
Algorithm Hash digest
SHA256 53560f67862b522fde35b127b8a1e6b543829d27ece13398136c64bb984a9fcb
MD5 c67e44121df8a8b31015edd01103b223
BLAKE2b-256 c17cab87a43f6a34dc4e20ffbcc90999f6ea29f6c8eb1fe4a9e594e734e63a38

See more details on using hashes here.

File details

Details for the file py_socialite-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: py_socialite-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for py_socialite-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 65800735785f09fbafe6def7b53adb197e78417014766cecc17642d384fc5ccc
MD5 bd25966608f458140eb54b9d225ac2b5
BLAKE2b-256 1048a4391df47edb3cc5f5d868668be5c10179e054b0bc5ec354cf6b9338bb7f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page