the37lab-authlib 0.1.1750143654__py3-none-any.whl → 0.1.1750187527__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.

the37lab_authlib/auth.py CHANGED
@@ -130,7 +130,7 @@ class AuthManager:
130
130
  app.register_blueprint(self.create_blueprint())
131
131
 
132
132
  def create_blueprint(self):
133
- bp = Blueprint('auth', __name__, url_prefix='/v1/users')
133
+ bp = Blueprint('auth', __name__, url_prefix='/api/v1/users')
134
134
 
135
135
  @bp.route('/login', methods=['POST'])
136
136
  @handle_auth_errors
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.4
2
+ Name: the37lab_authlib
3
+ Version: 0.1.1750187527
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 /api/v1/users/login` - Login with username/password
105
+ - **Request:** `{ "username": "string", "password": "string" }`
106
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
107
+ - `POST /api/v1/users/login/oauth` - Get OAuth redirect URL
108
+ - **Request:** `{ "provider": "google|github|..." }`
109
+ - **Response:** `{ "redirect_url": "string" }`
110
+ - `GET /api/v1/users/login/oauth2callback` - OAuth callback
111
+ - **Query Params:** `code`, `state`, `provider`
112
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
113
+ - `POST /api/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 /api/v1/users/register` - Register new user
119
+ - **Request:** `{ "username": "string", "password": "string", "email": "string", ... }`
120
+ - **Response:** `{ "user": { ... }, "token": "jwt", "refresh_token": "jwt" }`
121
+ - `GET /api/v1/users/login/profile` - Get user profile
122
+ - **Auth:** Bearer JWT
123
+ - **Response:** `{ "user": { ... } }`
124
+ - `GET /api/v1/users/roles` - Get available roles
125
+ - **Response:** `[ "admin", "user", ... ]`
126
+
127
+ ### API Tokens
128
+ - `POST /api/v1/users/{user}/api-tokens` - Create API token
129
+ - **Request:** `{ "name": "string", "scopes": [ ... ] }`
130
+ - **Response:** `{ "token": "string", "id": "uuid", ... }`
131
+ - `GET /api/v1/users/{user}/api-tokens` - List API tokens
132
+ - **Response:** `[ { "id": "uuid", "name": "string", ... } ]`
133
+ - `DELETE /api/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 `/api/v1/users/login`.
140
+ - Receives JWT and refresh token.
141
+ 2. **Token Refresh:**
142
+ - Use `/api/v1/users/token-refresh` with refresh token to get new JWT.
143
+ 3. **OAuth:**
144
+ - Get redirect URL from `/api/v1/users/login/oauth`.
145
+ - Complete OAuth flow via `/api/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
+ ```
@@ -1,10 +1,10 @@
1
1
  the37lab_authlib/__init__.py,sha256=cFVTWL-0YIMqwOMVy1P8mOt_bQODJp-L9bfp2QQ8CTo,132
2
- the37lab_authlib/auth.py,sha256=VP1_E7_iYkt5fzm6wYCx5Jx8kQtUVQjUcLIwYN9FVyw,20656
2
+ the37lab_authlib/auth.py,sha256=dQkE6z9GZZpnl0nfqulcveho8W5lM95XUBLmtE-5JIc,20660
3
3
  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.1750143654.dist-info/METADATA,sha256=Gt1614KadiUN-Lb-7wXfXasFTHgsVL9YKG1msLnWxCI,2662
8
- the37lab_authlib-0.1.1750143654.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- the37lab_authlib-0.1.1750143654.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
- the37lab_authlib-0.1.1750143654.dist-info/RECORD,,
7
+ the37lab_authlib-0.1.1750187527.dist-info/METADATA,sha256=I1q0GUs96_gBGEDq4no_p0t_UXXyw5IlWsPVbaJJTnM,5641
8
+ the37lab_authlib-0.1.1750187527.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ the37lab_authlib-0.1.1750187527.dist-info/top_level.txt,sha256=6Jmxw4UeLrhfJXgRKbXWY4OhxRSaMs0dKKhNCGWWSwc,17
10
+ the37lab_authlib-0.1.1750187527.dist-info/RECORD,,
@@ -1,114 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: the37lab_authlib
3
- Version: 0.1.1750143654
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.
21
-
22
- ## Table of Contents
23
- - [Installation](#installation)
24
- - [Quick Start](#quick-start)
25
- - [Configuration](#configuration)
26
- - [API Endpoints](#api-endpoints)
27
- - [Development](#development)
28
-
29
- ## Installation
30
-
31
- ```bash
32
- pip install -e .
33
- ```
34
-
35
- ## Quick Start
36
-
37
- ```python
38
- from flask import Flask
39
- from authlib import AuthManager
40
-
41
- app = Flask(__name__)
42
-
43
- auth = AuthManager(
44
- app=app,
45
- db_dsn="postgresql://user:pass@localhost/dbname",
46
- jwt_secret="your-secret-key",
47
- oauth_config={
48
- "google": {
49
- "client_id": "your-client-id",
50
- "client_secret": "your-client-secret"
51
- }
52
- }
53
- )
54
-
55
- @app.route("/protected")
56
- @auth.require_auth(roles=["admin"])
57
- def protected_route():
58
- return "Protected content"
59
- ```
60
-
61
- ## Configuration
62
-
63
- ### Required Parameters
64
- - `app`: Flask application instance
65
- - `db_dsn`: PostgreSQL connection string
66
- - `jwt_secret`: Secret key for JWT signing
67
-
68
- ### Optional Parameters
69
- - `oauth_config`: Dictionary of OAuth provider configurations
70
- - `token_expiry`: JWT token expiry time in seconds (default: 3600)
71
- - `refresh_token_expiry`: Refresh token expiry time in seconds (default: 2592000)
72
-
73
- ## API Endpoints
74
-
75
- ### Authentication
76
- - `POST /v1/users/login` - Login with username/password
77
- - `POST /v1/users/login/oauth` - Get OAuth redirect URL
78
- - `GET /v1/users/login/oauth2callback` - OAuth callback
79
- - `POST /v1/users/token-refresh` - Refresh JWT token
80
-
81
- ### User Management
82
- - `POST /v1/users/register` - Register new user
83
- - `GET /v1/users/login/profile` - Get user profile
84
- - `GET /v1/users/roles` - Get available roles
85
-
86
- ### API Tokens
87
- - `POST /v1/users/{user}/api-tokens` - Create API token
88
- - `GET /v1/users/{user}/api-tokens` - List API tokens
89
- - `DELETE /v1/users/{user}/api-tokens/{token_id}` - Delete API token
90
-
91
- ## Development
92
-
93
- ### Setup
94
- 1. Clone the repository
95
- 2. Create virtual environment:
96
- ```bash
97
- python -m venv venv
98
- venv\Scripts\activate
99
- ```
100
- 3. Install dependencies:
101
- ```bash
102
- pip install -e ".[dev]"
103
- ```
104
-
105
- ### Database Setup
106
- ```bash
107
- createdb authlib
108
- python -m authlib.cli db init
109
- ```
110
-
111
- ### Running Tests
112
- ```bash
113
- pytest
114
- ```