Skip to main content

A robust Python library for JWT, OAuth2, and database authentication.

Project description

Auth Plugin Library

Auth Plugin is a robust and flexible Python library designed to streamline the authentication process in web applications. It provides built-in support for JWT authentication, OAuth2 token management, and seamless database connectivity with MongoDB, PostgreSQL, and MySQL.

Features

  • JWT Authentication: Easily encode and decode JSON Web Tokens (JWTs) with built-in error handling and robust security.
  • OAuth2 Integration: Fetch and manage OAuth2 tokens with automatic error handling for HTTP requests and support for various grant types.
  • Database Connectivity: Connect to MongoDB, PostgreSQL, and MySQL databases with a simple API and proper connection management.
  • Robust Error Handling: Comprehensive try-except blocks across all operations, ensuring stability and reliability.
  • Configurable Logging: Detailed logging for all operations, including JWT processing, OAuth2 token management, and database connections.

Installation

To install the Auth Plugin library, use pip:

pip install auth-plugin

Usage

JWT Authentication

The JWT authentication module allows you to encode and decode JSON Web Tokens.

from auth_plugin.jwt_auth import JWTAuth

# Initialize the JWTAuth object with a secret key
jwt_auth = JWTAuth(secret_key="your_secret_key")

# Encode a payload to generate a JWT token
token = jwt_auth.encode_token({"user_id": 123})

# Decode the JWT token to retrieve the payload
payload = jwt_auth.decode_token(token)

Database Management

The DBManager class supports connections to MongoDB, PostgreSQL, and MySQL. Use the appropriate database type when initializing the object.

from auth_plugin.db_manager import DBManager

# MongoDB
db_manager = DBManager(
    db_type="mongodb", # or "mongo"
    host="localhost",
    port=27017,
    db_name="testdb"
)

# PostgreSQL
db_manager = DBManager(
    db_type="postgresql",
    user="username",
    password="password",
    host="localhost",
    port=5432,
    db_name="testdb"
)

# MySQL
db_manager = DBManager(
    db_type="mysql",
    user="username",
    password="password",
    host="localhost",
    db_name="testdb"
)

OAuth2 Authentication

The OAuth2 authentication module allows you to obtain access tokens using the OAuth2 protocol.

from auth_plugin.oauth2_auth import OAuth2Auth

# Initialize the OAuth2Auth object with client credentials and token URL
oauth2 = OAuth2Auth(
    client_id="your_client_id",
    client_secret="your_client_secret",
    redirect_uri="http://localhost/callback",
    auth_url="https://example.com/oauth2/authorize",
    token_url="https://example.com/oauth2/token"
)

# Generate the authorization URL
authorization_url = oauth2.get_authorization_url()

# Exchange the authorization code for an access token
access_token = oauth2.get_access_token(code="authorization_code")

Documentation

For detailed usage instructions, examples, and API reference, please refer to the official documentation.

Contributing

Contributions are welcome! If you'd like to contribute to the Auth Plugin library, please follow our contributing guidelines. Ensure you have reviewed the guidelines before submitting a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

auth_plugin-0.3.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

auth_plugin-0.3.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file auth_plugin-0.3.0.tar.gz.

File metadata

  • Download URL: auth_plugin-0.3.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for auth_plugin-0.3.0.tar.gz
Algorithm Hash digest
SHA256 84dcc777c44387f3a141fdc4661a12f8168b1d3262e6bde0962d9c2920f8f218
MD5 7a05833e45a7420138fd4023ab0f6851
BLAKE2b-256 edfc6e91de1e04c79c9b8615592c04e3b49372dee0ca71292e03031d6f5469fc

See more details on using hashes here.

File details

Details for the file auth_plugin-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: auth_plugin-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for auth_plugin-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d72a85d739b9ff8ef264099e4386b05bb87e1b4c583c8ef7717a9d80eaa38c3
MD5 76fbc5ed2bff00d3543b23f5c8505fcc
BLAKE2b-256 bac5b0f9834824dbf80bc6395b327ef5230c13283964402eeeaf399266cd7eb7

See more details on using hashes here.

Supported by

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