the37lab-authlib 0.1.1749556774__py3-none-any.whl → 0.1.1750156111__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of the37lab-authlib might be problematic. Click here for more details.

@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.4
2
+ Name: the37lab_authlib
3
+ Version: 0.1.1750156111
4
+ Summary: Python SDK for the Authlib
5
+ Author-email: the37lab <info@the37lab.com>
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Operating System :: OS Independent
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: flask
11
+ Requires-Dist: psycopg2-binary
12
+ Requires-Dist: pyjwt
13
+ Requires-Dist: python-dotenv
14
+ Requires-Dist: requests
15
+ Requires-Dist: authlib
16
+ Requires-Dist: bcrypt
17
+
18
+ # AuthLib
19
+
20
+ A Python authentication library that provides JWT, OAuth2, and API token authentication with PostgreSQL backend. This library is designed for seamless integration with Flask applications and provides a robust set of endpoints and utilities for user management, authentication, and API token handling.
21
+
22
+ ## Table of Contents
23
+ - [AuthLib](#authlib)
24
+ - [Table of Contents](#table-of-contents)
25
+ - [Installation](#installation)
26
+ - [Quick Start](#quick-start)
27
+ - [Configuration](#configuration)
28
+ - [Required Parameters](#required-parameters)
29
+ - [Optional Parameters](#optional-parameters)
30
+ - [Example `oauth_config`:](#example-oauth_config)
31
+ - [API Endpoints](#api-endpoints)
32
+ - [Authentication](#authentication)
33
+ - [User Management](#user-management)
34
+ - [API Tokens](#api-tokens)
35
+ - [Authentication Flow](#authentication-flow)
36
+ - [User Object](#user-object)
37
+ - [Token Management](#token-management)
38
+ - [Development](#development)
39
+ - [Setup](#setup)
40
+ - [Database Setup](#database-setup)
41
+ - [Running Tests](#running-tests)
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install -e .
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ```python
52
+ from flask import Flask
53
+ from authlib import AuthManager
54
+
55
+ app = Flask(__name__)
56
+
57
+ auth = AuthManager(
58
+ app=app,
59
+ db_dsn="postgresql://user:pass@localhost/dbname",
60
+ jwt_secret="your-secret-key",
61
+ oauth_config={
62
+ "google": {
63
+ "client_id": "your-client-id",
64
+ "client_secret": "your-client-secret"
65
+ }
66
+ }
67
+ )
68
+
69
+ @app.route("/protected")
70
+ @auth.require_auth(roles=["admin"])
71
+ def protected_route():
72
+ return "Protected content"
73
+ ```
74
+
75
+ ## Configuration
76
+
77
+ ### Required Parameters
78
+ - `app`: Flask application instance
79
+ - `db_dsn`: PostgreSQL connection string
80
+ - `jwt_secret`: Secret key for JWT signing
81
+
82
+ ### Optional Parameters
83
+ - `oauth_config`: Dictionary of OAuth provider configurations (see below)
84
+ - `token_expiry`: JWT token expiry time in seconds (default: 3600)
85
+ - `refresh_token_expiry`: Refresh token expiry time in seconds (default: 2592000)
86
+
87
+ #### Example `oauth_config`:
88
+ ```python
89
+ {
90
+ "google": {
91
+ "client_id": "...",
92
+ "client_secret": "..."
93
+ },
94
+ "github": {
95
+ "client_id": "...",
96
+ "client_secret": "..."
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## API Endpoints
102
+
103
+ ### Authentication
104
+ - `POST /v1/users/login` - Login with username/password
105
+ - **Request:** `{ "username": "string", "password": "string" }`
106
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
107
+ - `POST /v1/users/login/oauth` - Get OAuth redirect URL
108
+ - **Request:** `{ "provider": "google|github|..." }`
109
+ - **Response:** `{ "redirect_url": "string" }`
110
+ - `GET /v1/users/login/oauth2callback` - OAuth callback
111
+ - **Query Params:** `code`, `state`, `provider`
112
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
113
+ - `POST /v1/users/token-refresh` - Refresh JWT token
114
+ - **Request:** `{ "refresh_token": "jwt" }`
115
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt" }`
116
+
117
+ ### User Management
118
+ - `POST /v1/users/register` - Register new user
119
+ - **Request:** `{ "username": "string", "password": "string", "email": "string", ... }`
120
+ - **Response:** `{ "user": { ... }, "token": "jwt", "refresh_token": "jwt" }`
121
+ - `GET /v1/users/login/profile` - Get user profile
122
+ - **Auth:** Bearer JWT
123
+ - **Response:** `{ "user": { ... } }`
124
+ - `GET /v1/users/roles` - Get available roles
125
+ - **Response:** `[ "admin", "user", ... ]`
126
+
127
+ ### API Tokens
128
+ - `POST /v1/users/{user}/api-tokens` - Create API token
129
+ - **Request:** `{ "name": "string", "scopes": [ ... ] }`
130
+ - **Response:** `{ "token": "string", "id": "uuid", ... }`
131
+ - `GET /v1/users/{user}/api-tokens` - List API tokens
132
+ - **Response:** `[ { "id": "uuid", "name": "string", ... } ]`
133
+ - `DELETE /v1/users/{user}/api-tokens/{token_id}` - Delete API token
134
+ - **Response:** `{ "success": true }`
135
+
136
+ ## Authentication Flow
137
+
138
+ 1. **Login:**
139
+ - User submits credentials to `/v1/users/login`.
140
+ - Receives JWT and refresh token.
141
+ 2. **Token Refresh:**
142
+ - Use `/v1/users/token-refresh` with refresh token to get new JWT.
143
+ 3. **OAuth:**
144
+ - Get redirect URL from `/v1/users/login/oauth`.
145
+ - Complete OAuth flow via `/v1/users/login/oauth2callback`.
146
+ 4. **Protected Routes:**
147
+ - Use `@auth.require_auth()` decorator to protect Flask routes.
148
+
149
+ ## User Object
150
+
151
+ The user object returned by the API typically includes:
152
+ ```json
153
+ {
154
+ "id": "uuid",
155
+ "username": "string",
156
+ "email": "string",
157
+ "roles": ["user", "admin"],
158
+ "created_at": "timestamp",
159
+ "last_login": "timestamp"
160
+ }
161
+ ```
162
+
163
+ ## Token Management
164
+ - **JWT:** Used for authenticating API requests. Include in `Authorization: Bearer <token>` header.
165
+ - **Refresh Token:** Used to obtain new JWTs without re-authenticating.
166
+ - **API Tokens:** Long-lived tokens for programmatic access, managed per user.
167
+
168
+ ## Development
169
+
170
+ ### Setup
171
+ 1. Clone the repository
172
+ 2. Create virtual environment:
173
+ ```bash
174
+ python -m venv venv
175
+ venv\Scripts\activate
176
+ ```
177
+ 3. Install dependencies:
178
+ ```bash
179
+ pip install -e ".[dev]"
180
+ ```
181
+
182
+ ### Database Setup
183
+ ```bash
184
+ createdb authlib
185
+ python -m authlib.cli db init
186
+ ```
187
+
188
+ ### Running Tests
189
+ ```bash
190
+ pytest
191
+ ```
@@ -4,7 +4,7 @@ the37lab_authlib/db.py,sha256=fTXxnfju0lmbFGPVbXpTMeDmJMeBgURVZTndyxyRyCc,2734
4
4
  the37lab_authlib/decorators.py,sha256=AEQfix31fHUZvhEZd4Ud8Zh2KBGjV6O_braiPL-BU7w,1219
5
5
  the37lab_authlib/exceptions.py,sha256=mdplK5sKNtagPAzSGq5NGsrQ4r-k03DKJBKx6myWwZc,317
6
6
  the37lab_authlib/models.py,sha256=-PlvQlHGIsSdrH0H9Cdh_vTPlltGV8G1Z1mmGQvAg9Y,3422
7
- the37lab_authlib-0.1.1749556774.dist-info/METADATA,sha256=z-lj2n8i0V4dArH4VC4PgxS1v7EFJPAtkiNqxCcpXgk,2711
8
- the37lab_authlib-0.1.1749556774.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- the37lab_authlib-0.1.1749556774.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
- the37lab_authlib-0.1.1749556774.dist-info/RECORD,,
7
+ the37lab_authlib-0.1.1750156111.dist-info/METADATA,sha256=ZzZKnxoba2xGq-V05gzIf_Wqy4P6HNkq_aKU64BbwqI,5585
8
+ the37lab_authlib-0.1.1750156111.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ the37lab_authlib-0.1.1750156111.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
+ the37lab_authlib-0.1.1750156111.dist-info/RECORD,,
@@ -1,115 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: the37lab_authlib
3
- Version: 0.1.1749556774
4
- Summary: Python SDK for the Authlib
5
- Author-email: the37lab <info@the37lab.com>
6
- Classifier: Programming Language :: Python :: 3
7
- Classifier: License :: Other/Proprietary License
8
- Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.9
10
- Description-Content-Type: text/markdown
11
- Requires-Dist: flask
12
- Requires-Dist: psycopg2-binary
13
- Requires-Dist: pyjwt
14
- Requires-Dist: python-dotenv
15
- Requires-Dist: requests
16
- Requires-Dist: authlib
17
- Requires-Dist: bcrypt
18
-
19
- # AuthLib
20
-
21
- A Python authentication library that provides JWT, OAuth2, and API token authentication with PostgreSQL backend.
22
-
23
- ## Table of Contents
24
- - [Installation](#installation)
25
- - [Quick Start](#quick-start)
26
- - [Configuration](#configuration)
27
- - [API Endpoints](#api-endpoints)
28
- - [Development](#development)
29
-
30
- ## Installation
31
-
32
- ```bash
33
- pip install -e .
34
- ```
35
-
36
- ## Quick Start
37
-
38
- ```python
39
- from flask import Flask
40
- from authlib import AuthManager
41
-
42
- app = Flask(__name__)
43
-
44
- auth = AuthManager(
45
- app=app,
46
- db_dsn="postgresql://user:pass@localhost/dbname",
47
- jwt_secret="your-secret-key",
48
- oauth_config={
49
- "google": {
50
- "client_id": "your-client-id",
51
- "client_secret": "your-client-secret"
52
- }
53
- }
54
- )
55
-
56
- @app.route("/protected")
57
- @auth.require_auth(roles=["admin"])
58
- def protected_route():
59
- return "Protected content"
60
- ```
61
-
62
- ## Configuration
63
-
64
- ### Required Parameters
65
- - `app`: Flask application instance
66
- - `db_dsn`: PostgreSQL connection string
67
- - `jwt_secret`: Secret key for JWT signing
68
-
69
- ### Optional Parameters
70
- - `oauth_config`: Dictionary of OAuth provider configurations
71
- - `token_expiry`: JWT token expiry time in seconds (default: 3600)
72
- - `refresh_token_expiry`: Refresh token expiry time in seconds (default: 2592000)
73
-
74
- ## API Endpoints
75
-
76
- ### Authentication
77
- - `POST /v1/users/login` - Login with username/password
78
- - `POST /v1/users/login/oauth` - Get OAuth redirect URL
79
- - `GET /v1/users/login/oauth2callback` - OAuth callback
80
- - `POST /v1/users/token-refresh` - Refresh JWT token
81
-
82
- ### User Management
83
- - `POST /v1/users/register` - Register new user
84
- - `GET /v1/users/login/profile` - Get user profile
85
- - `GET /v1/users/roles` - Get available roles
86
-
87
- ### API Tokens
88
- - `POST /v1/users/{user}/api-tokens` - Create API token
89
- - `GET /v1/users/{user}/api-tokens` - List API tokens
90
- - `DELETE /v1/users/{user}/api-tokens/{token_id}` - Delete API token
91
-
92
- ## Development
93
-
94
- ### Setup
95
- 1. Clone the repository
96
- 2. Create virtual environment:
97
- ```bash
98
- python -m venv venv
99
- venv\Scripts\activate
100
- ```
101
- 3. Install dependencies:
102
- ```bash
103
- pip install -e ".[dev]"
104
- ```
105
-
106
- ### Database Setup
107
- ```bash
108
- createdb authlib
109
- python -m authlib.cli db init
110
- ```
111
-
112
- ### Running Tests
113
- ```bash
114
- pytest
115
- ```