{"id":34029748,"url":"https://github.com/viseshagarwal/auth-plugin","last_synced_at":"2026-04-01T23:37:46.753Z","repository":{"id":255610170,"uuid":"853169098","full_name":"viseshagarwal/auth-plugin","owner":"viseshagarwal","description":"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.","archived":false,"fork":false,"pushed_at":"2024-10-31T17:12:24.000Z","size":91,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-03T06:04:17.216Z","etag":null,"topics":["authentication","database","jwt-authentication","mongodb","oauth2"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/auth-plugin/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/viseshagarwal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-06T05:58:28.000Z","updated_at":"2024-10-31T17:12:27.000Z","dependencies_parsed_at":"2024-09-06T09:42:40.681Z","dependency_job_id":"7682d78f-5acc-4dbc-9acb-bdc68b1b0dd9","html_url":"https://github.com/viseshagarwal/auth-plugin","commit_stats":null,"previous_names":["viseshagarwal/auth-plugin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/viseshagarwal/auth-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viseshagarwal%2Fauth-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viseshagarwal%2Fauth-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viseshagarwal%2Fauth-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viseshagarwal%2Fauth-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viseshagarwal","download_url":"https://codeload.github.com/viseshagarwal/auth-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viseshagarwal%2Fauth-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31292987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T21:15:39.731Z","status":"ssl_error","status_checked_at":"2026-04-01T21:15:34.046Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","database","jwt-authentication","mongodb","oauth2"],"created_at":"2025-12-13T17:51:21.850Z","updated_at":"2026-04-01T23:37:46.747Z","avatar_url":"https://github.com/viseshagarwal.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Auth Plugin Library\n\n**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.\n\n## Features\n\n- **JWT Authentication**: Easily encode and decode JSON Web Tokens (JWTs) with built-in error handling and robust security.\n- **OAuth2 Integration**: Fetch and manage OAuth2 tokens with automatic error handling for HTTP requests and support for various grant types.\n- **Database Connectivity**: Connect to MongoDB, PostgreSQL, and MySQL databases with a simple API and proper connection management.\n- **Robust Error Handling**: Comprehensive `try-except` blocks across all operations, ensuring stability and reliability.\n- **Configurable Logging**: Detailed logging for all operations, including JWT processing, OAuth2 token management, and database connections.\n\n## Installation\n\nTo install the Auth Plugin library, use pip:\n\n```bash\npip install auth-plugin\n```\n\n## Usage\n\n### JWT Authentication\n\nThe JWT authentication module allows you to encode and decode JSON Web Tokens.\n\n```python\nfrom auth_plugin.jwt_auth import JWTAuth\n\n# Initialize the JWTAuth object with a secret key\njwt_auth = JWTAuth(secret_key=\"your_secret_key\")\n\n# Encode a payload to generate a JWT token\ntoken = jwt_auth.encode_token({\"user_id\": 123})\n\n# Decode the JWT token to retrieve the payload\npayload = jwt_auth.decode_token(token)\n```\n\n### Database Management\n\nThe `DBManager` class supports connections to MongoDB, PostgreSQL and MySQL. Use the appropriate database type when initializing the object.\n\n#### MongoDB\n\n```python\nfrom auth_plugin.db_manager import DBManager\n\ndb_manager = DBManager(\n    db_type=\"mongodb\",  # or \"mongo\"\n    host=\"localhost\",\n    port=27017,\n    db_name=\"testdb\"\n)\n```\n\n#### PostgreSQL\n\n```python\ndb_manager = DBManager(\n    db_type=\"postgres\",\n    user=\"username\",\n    password=\"password\",\n    host=\"localhost\",\n    port=5432,\n    db_name=\"testdb\"\n)\n```\n\n#### MySQL\n\n```python\ndb_manager = DBManager(\n    db_type=\"mysql\",\n    user=\"username\",\n    password=\"password\",\n    host=\"localhost\",\n    db_name=\"testdb\"\n)\n```\n\n### Query Execution for All Supported Databases\n\nThe `DBManager` class provides methods for executing queries and fetching results. The behavior is different depending on whether you're using an SQL database (PostgreSQL, MySQL, SQLite) or a NoSQL database like MongoDB.\n\n#### SQL Databases (PostgreSQL, MySQL)\n\nFor SQL-based databases (PostgreSQL and MySQL), you can execute SQL queries and fetch results using the following methods:\n\n```python\n# Execute a query (e.g., creating a table)\ndb_manager.execute_query(\"CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name VARCHAR(255))\")\n\n# Insert data into the table\ndb_manager.execute_query(\"INSERT INTO users (name) VALUES (%s)\", (\"John Doe\",))\n\n# Fetch all results from a table\ndb_manager.execute_query(\"SELECT * FROM users\")\nresults = db_manager.fetch_results()\nprint(results)\n```\n\n#### MongoDB\n\nFor MongoDB, you can interact with collections using the `get_collection` method, and perform operations like inserting or querying documents.\n\n```python\n# Get a collection\ncollection = db_manager.get_collection(\"users\")\n\n# Insert a document into the collection\ncollection.insert_one({\"name\": \"John Doe\"})\n\n# Query documents from the collection\nresults = collection.find({\"name\": \"John Doe\"})\nfor doc in results:\n    print(doc)\n```\n\n### Closing the Connection\n\nAfter executing queries or performing operations, don't forget to close the connection.\n\n```python\ndb_manager.close()\n```\n\n### OAuth2 Authentication\n\nThe OAuth2 authentication module allows you to obtain access tokens using the OAuth2 protocol.\n\n```python\nfrom auth_plugin.oauth2_auth import OAuth2Auth\n\n# Initialize the OAuth2Auth object with client credentials and token URL\noauth2 = OAuth2Auth(\n    client_id=\"your_client_id\",\n    client_secret=\"your_client_secret\",\n    redirect_uri=\"http://localhost/callback\",\n    auth_url=\"https://example.com/oauth2/authorize\",\n    token_url=\"https://example.com/oauth2/token\"\n)\n\n# Generate the authorization URL\nauthorization_url = oauth2.get_authorization_url()\n\n# Exchange the authorization code for an access token\naccess_token = oauth2.get_access_token(code=\"authorization_code\")\n```\n\n## Documentation\n\nFor detailed usage instructions, examples, and API reference, please refer to the [official documentation](https://github.com/viseshagarwal/auth-plugin).\n\n## Contributing\n\nContributions are welcome! If you'd like to contribute to the Auth Plugin library, please follow our [contributing guidelines](https://github.com/viseshagarwal/auth-plugin). Ensure you have reviewed the guidelines before submitting a pull request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/viseshagarwal/auth-plugin/blob/main/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviseshagarwal%2Fauth-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviseshagarwal%2Fauth-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviseshagarwal%2Fauth-plugin/lists"}