the37lab-authlib 0.1.1750844514__tar.gz → 0.1.1750952155__tar.gz

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.

Files changed (15) hide show
  1. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/PKG-INFO +1 -1
  2. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/README.md +189 -189
  3. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/pyproject.toml +15 -15
  4. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib/__init__.py +4 -4
  5. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib/auth.py +527 -527
  6. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib/db.py +73 -73
  7. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib/decorators.py +32 -30
  8. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib/exceptions.py +10 -10
  9. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib/models.py +94 -94
  10. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib.egg-info/PKG-INFO +1 -1
  11. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/setup.cfg +0 -0
  12. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib.egg-info/SOURCES.txt +0 -0
  13. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib.egg-info/dependency_links.txt +0 -0
  14. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib.egg-info/requires.txt +0 -0
  15. {the37lab_authlib-0.1.1750844514 → the37lab_authlib-0.1.1750952155}/src/the37lab_authlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: the37lab_authlib
3
- Version: 0.1.1750844514
3
+ Version: 0.1.1750952155
4
4
  Summary: Python SDK for the Authlib
5
5
  Author-email: the37lab <info@the37lab.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,189 +1,189 @@
1
- # AuthLib
2
-
3
- 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.
4
-
5
- ## Table of Contents
6
- - [AuthLib](#authlib)
7
- - [Table of Contents](#table-of-contents)
8
- - [Installation](#installation)
9
- - [Quick Start](#quick-start)
10
- - [Configuration](#configuration)
11
- - [Required Parameters](#required-parameters)
12
- - [Optional Parameters](#optional-parameters)
13
- - [Example `oauth_config`:](#example-oauth_config)
14
- - [API Endpoints](#api-endpoints)
15
- - [Authentication](#authentication)
16
- - [User Management](#user-management)
17
- - [API Tokens](#api-tokens)
18
- - [Authentication Flow](#authentication-flow)
19
- - [User Object](#user-object)
20
- - [Token Management](#token-management)
21
- - [Development](#development)
22
- - [Setup](#setup)
23
- - [Database Setup](#database-setup)
24
- - [Running Tests](#running-tests)
25
-
26
- ## Installation
27
-
28
- ```bash
29
- pip install -e .
30
- ```
31
-
32
- ## Quick Start
33
-
34
- ```python
35
- from flask import Flask
36
- from authlib import AuthManager
37
-
38
- app = Flask(__name__)
39
-
40
- auth = AuthManager(
41
- app=app,
42
- db_dsn="postgresql://user:pass@localhost/dbname",
43
- jwt_secret="your-secret-key",
44
- oauth_config={
45
- "google": {
46
- "client_id": "your-client-id",
47
- "client_secret": "your-client-secret"
48
- }
49
- }
50
- )
51
-
52
- @app.route("/protected")
53
- @auth.require_auth(roles=["admin"])
54
- def protected_route():
55
- return "Protected content"
56
-
57
- @app.route("/public")
58
- @auth.public_endpoint
59
- def custom_public_route():
60
- return "Public content"
61
- ```
62
-
63
- `AuthManager`'s blueprint now registers a global error handler for
64
- `AuthError` and authenticates requests for all of its routes by default.
65
- Authenticated users are made available as `flask.g.requesting_user`.
66
- Only the login, OAuth, token refresh, registration and role listing
67
- endpoints are exempt from this check. Additional routes can be marked as
68
- public using the `@auth.public_endpoint` decorator or
69
- `auth.add_public_endpoint("auth.some_endpoint")`.
70
-
71
- ## Configuration
72
-
73
- ### Required Parameters
74
- - `app`: Flask application instance
75
- - `db_dsn`: PostgreSQL connection string
76
- - `jwt_secret`: Secret key for JWT signing
77
-
78
- ### Optional Parameters
79
- - `oauth_config`: Dictionary of OAuth provider configurations (see below)
80
- - `token_expiry`: JWT token expiry time in seconds (default: 3600)
81
- - `refresh_token_expiry`: Refresh token expiry time in seconds (default: 2592000)
82
-
83
- #### Example `oauth_config`:
84
- ```python
85
- {
86
- "google": {
87
- "client_id": "...",
88
- "client_secret": "..."
89
- },
90
- "github": {
91
- "client_id": "...",
92
- "client_secret": "..."
93
- }
94
- }
95
- ```
96
-
97
- ## API Endpoints
98
-
99
- ### Authentication
100
- - `POST /api/v1/users/login` - Login with username/password
101
- - **Request:** `{ "username": "string", "password": "string" }`
102
- - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
103
- - `POST /api/v1/users/login/oauth` - Get OAuth redirect URL
104
- - **Request:** `{ "provider": "google|github|..." }`
105
- - **Response:** `{ "redirect_url": "string" }`
106
- - `GET /api/v1/users/login/oauth2callback` - OAuth callback
107
- - **Query Params:** `code`, `state`, `provider`
108
- - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
109
- - `POST /api/v1/users/token-refresh` - Refresh JWT token
110
- - **Request:** `{ "refresh_token": "jwt" }`
111
- - **Response:** `{ "token": "jwt", "refresh_token": "jwt" }`
112
-
113
- ### User Management
114
- - `POST /api/v1/users/register` - Register new user
115
- - **Request:** `{ "username": "string", "password": "string", "email": "string", ... }`
116
- - **Response:** `{ "user": { ... }, "token": "jwt", "refresh_token": "jwt" }`
117
- - `GET /api/v1/users/login/profile` - Get user profile
118
- - **Auth:** Bearer JWT
119
- - **Response:** `{ "user": { ... } }`
120
- - `GET /api/v1/users/roles` - Get available roles
121
- - **Response:** `[ "admin", "user", ... ]`
122
-
123
- ### API Tokens
124
- - `POST /api/v1/users/{user}/api-tokens` - Create API token
125
- - **Request:** `{ "name": "string", "scopes": [ ... ] }`
126
- - **Response:** `{ "token": "string", "id": "uuid", ... }`
127
- - `GET /api/v1/users/{user}/api-tokens` - List API tokens
128
- - **Response:** `[ { "id": "uuid", "name": "string", ... } ]`
129
- - `DELETE /api/v1/users/{user}/api-tokens/{token_id}` - Delete API token
130
- - **Response:** `{ "success": true }`
131
-
132
- ## Authentication Flow
133
-
134
- 1. **Login:**
135
- - User submits credentials to `/api/v1/users/login`.
136
- - Receives JWT and refresh token.
137
- 2. **Token Refresh:**
138
- - Use `/api/v1/users/token-refresh` with refresh token to get new JWT.
139
- 3. **OAuth:**
140
- - Get redirect URL from `/api/v1/users/login/oauth`.
141
- - Complete OAuth flow via `/api/v1/users/login/oauth2callback`.
142
- 4. **Protected Routes:**
143
- - All routes inside the provided blueprint are authenticated by default.
144
- The authenticated user can be accessed via `g.requesting_user`.
145
- Use `@auth.require_auth()` to protect custom routes in your application.
146
-
147
- ## User Object
148
-
149
- The user object returned by the API typically includes:
150
- ```json
151
- {
152
- "id": "uuid",
153
- "username": "string",
154
- "email": "string",
155
- "roles": ["user", "admin"],
156
- "created_at": "timestamp",
157
- "last_login": "timestamp"
158
- }
159
- ```
160
-
161
- ## Token Management
162
- - **JWT:** Used for authenticating API requests. Include in `Authorization: Bearer <token>` header.
163
- - **Refresh Token:** Used to obtain new JWTs without re-authenticating.
164
- - **API Tokens:** Long-lived tokens for programmatic access, managed per user.
165
-
166
- ## Development
167
-
168
- ### Setup
169
- 1. Clone the repository
170
- 2. Create virtual environment:
171
- ```bash
172
- python -m venv venv
173
- venv\Scripts\activate
174
- ```
175
- 3. Install dependencies:
176
- ```bash
177
- pip install -e ".[dev]"
178
- ```
179
-
180
- ### Database Setup
181
- ```bash
182
- createdb authlib
183
- python -m authlib.cli db init
184
- ```
185
-
186
- ### Running Tests
187
- ```bash
188
- pytest
189
- ```
1
+ # AuthLib
2
+
3
+ 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.
4
+
5
+ ## Table of Contents
6
+ - [AuthLib](#authlib)
7
+ - [Table of Contents](#table-of-contents)
8
+ - [Installation](#installation)
9
+ - [Quick Start](#quick-start)
10
+ - [Configuration](#configuration)
11
+ - [Required Parameters](#required-parameters)
12
+ - [Optional Parameters](#optional-parameters)
13
+ - [Example `oauth_config`:](#example-oauth_config)
14
+ - [API Endpoints](#api-endpoints)
15
+ - [Authentication](#authentication)
16
+ - [User Management](#user-management)
17
+ - [API Tokens](#api-tokens)
18
+ - [Authentication Flow](#authentication-flow)
19
+ - [User Object](#user-object)
20
+ - [Token Management](#token-management)
21
+ - [Development](#development)
22
+ - [Setup](#setup)
23
+ - [Database Setup](#database-setup)
24
+ - [Running Tests](#running-tests)
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install -e .
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ```python
35
+ from flask import Flask
36
+ from authlib import AuthManager
37
+
38
+ app = Flask(__name__)
39
+
40
+ auth = AuthManager(
41
+ app=app,
42
+ db_dsn="postgresql://user:pass@localhost/dbname",
43
+ jwt_secret="your-secret-key",
44
+ oauth_config={
45
+ "google": {
46
+ "client_id": "your-client-id",
47
+ "client_secret": "your-client-secret"
48
+ }
49
+ }
50
+ )
51
+
52
+ @app.route("/protected")
53
+ @auth.require_auth(roles=["admin"])
54
+ def protected_route():
55
+ return "Protected content"
56
+
57
+ @app.route("/public")
58
+ @auth.public_endpoint
59
+ def custom_public_route():
60
+ return "Public content"
61
+ ```
62
+
63
+ `AuthManager`'s blueprint now registers a global error handler for
64
+ `AuthError` and authenticates requests for all of its routes by default.
65
+ Authenticated users are made available as `flask.g.requesting_user`.
66
+ Only the login, OAuth, token refresh, registration and role listing
67
+ endpoints are exempt from this check. Additional routes can be marked as
68
+ public using the `@auth.public_endpoint` decorator or
69
+ `auth.add_public_endpoint("auth.some_endpoint")`.
70
+
71
+ ## Configuration
72
+
73
+ ### Required Parameters
74
+ - `app`: Flask application instance
75
+ - `db_dsn`: PostgreSQL connection string
76
+ - `jwt_secret`: Secret key for JWT signing
77
+
78
+ ### Optional Parameters
79
+ - `oauth_config`: Dictionary of OAuth provider configurations (see below)
80
+ - `token_expiry`: JWT token expiry time in seconds (default: 3600)
81
+ - `refresh_token_expiry`: Refresh token expiry time in seconds (default: 2592000)
82
+
83
+ #### Example `oauth_config`:
84
+ ```python
85
+ {
86
+ "google": {
87
+ "client_id": "...",
88
+ "client_secret": "..."
89
+ },
90
+ "github": {
91
+ "client_id": "...",
92
+ "client_secret": "..."
93
+ }
94
+ }
95
+ ```
96
+
97
+ ## API Endpoints
98
+
99
+ ### Authentication
100
+ - `POST /api/v1/users/login` - Login with username/password
101
+ - **Request:** `{ "username": "string", "password": "string" }`
102
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
103
+ - `POST /api/v1/users/login/oauth` - Get OAuth redirect URL
104
+ - **Request:** `{ "provider": "google|github|..." }`
105
+ - **Response:** `{ "redirect_url": "string" }`
106
+ - `GET /api/v1/users/login/oauth2callback` - OAuth callback
107
+ - **Query Params:** `code`, `state`, `provider`
108
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt", "user": { ... } }`
109
+ - `POST /api/v1/users/token-refresh` - Refresh JWT token
110
+ - **Request:** `{ "refresh_token": "jwt" }`
111
+ - **Response:** `{ "token": "jwt", "refresh_token": "jwt" }`
112
+
113
+ ### User Management
114
+ - `POST /api/v1/users/register` - Register new user
115
+ - **Request:** `{ "username": "string", "password": "string", "email": "string", ... }`
116
+ - **Response:** `{ "user": { ... }, "token": "jwt", "refresh_token": "jwt" }`
117
+ - `GET /api/v1/users/login/profile` - Get user profile
118
+ - **Auth:** Bearer JWT
119
+ - **Response:** `{ "user": { ... } }`
120
+ - `GET /api/v1/users/roles` - Get available roles
121
+ - **Response:** `[ "admin", "user", ... ]`
122
+
123
+ ### API Tokens
124
+ - `POST /api/v1/users/{user}/api-tokens` - Create API token
125
+ - **Request:** `{ "name": "string", "scopes": [ ... ] }`
126
+ - **Response:** `{ "token": "string", "id": "uuid", ... }`
127
+ - `GET /api/v1/users/{user}/api-tokens` - List API tokens
128
+ - **Response:** `[ { "id": "uuid", "name": "string", ... } ]`
129
+ - `DELETE /api/v1/users/{user}/api-tokens/{token_id}` - Delete API token
130
+ - **Response:** `{ "success": true }`
131
+
132
+ ## Authentication Flow
133
+
134
+ 1. **Login:**
135
+ - User submits credentials to `/api/v1/users/login`.
136
+ - Receives JWT and refresh token.
137
+ 2. **Token Refresh:**
138
+ - Use `/api/v1/users/token-refresh` with refresh token to get new JWT.
139
+ 3. **OAuth:**
140
+ - Get redirect URL from `/api/v1/users/login/oauth`.
141
+ - Complete OAuth flow via `/api/v1/users/login/oauth2callback`.
142
+ 4. **Protected Routes:**
143
+ - All routes inside the provided blueprint are authenticated by default.
144
+ The authenticated user can be accessed via `g.requesting_user`.
145
+ Use `@auth.require_auth()` to protect custom routes in your application.
146
+
147
+ ## User Object
148
+
149
+ The user object returned by the API typically includes:
150
+ ```json
151
+ {
152
+ "id": "uuid",
153
+ "username": "string",
154
+ "email": "string",
155
+ "roles": ["user", "admin"],
156
+ "created_at": "timestamp",
157
+ "last_login": "timestamp"
158
+ }
159
+ ```
160
+
161
+ ## Token Management
162
+ - **JWT:** Used for authenticating API requests. Include in `Authorization: Bearer <token>` header.
163
+ - **Refresh Token:** Used to obtain new JWTs without re-authenticating.
164
+ - **API Tokens:** Long-lived tokens for programmatic access, managed per user.
165
+
166
+ ## Development
167
+
168
+ ### Setup
169
+ 1. Clone the repository
170
+ 2. Create virtual environment:
171
+ ```bash
172
+ python -m venv venv
173
+ venv\Scripts\activate
174
+ ```
175
+ 3. Install dependencies:
176
+ ```bash
177
+ pip install -e ".[dev]"
178
+ ```
179
+
180
+ ### Database Setup
181
+ ```bash
182
+ createdb authlib
183
+ python -m authlib.cli db init
184
+ ```
185
+
186
+ ### Running Tests
187
+ ```bash
188
+ pytest
189
+ ```
@@ -1,16 +1,16 @@
1
- [build-system]
2
- requires = ["setuptools", "wheel"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "the37lab_authlib"
7
- version = "0.1.1750844514"
8
- description = "Python SDK for the Authlib"
9
- authors = [{name = "the37lab", email = "info@the37lab.com"}]
10
- dependencies = ["flask", "psycopg2-binary", "pyjwt", "python-dotenv", "requests", "authlib", "bcrypt"]
11
- requires-python = ">=3.9"
12
- readme = "README.md"
13
- classifiers = [
14
- "Programming Language :: Python :: 3",
15
- "Operating System :: OS Independent",
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "the37lab_authlib"
7
+ version = "0.1.1750952155"
8
+ description = "Python SDK for the Authlib"
9
+ authors = [{name = "the37lab", email = "info@the37lab.com"}]
10
+ dependencies = ["flask", "psycopg2-binary", "pyjwt", "python-dotenv", "requests", "authlib", "bcrypt"]
11
+ requires-python = ">=3.9"
12
+ readme = "README.md"
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: OS Independent",
16
16
  ]
@@ -1,5 +1,5 @@
1
- from .auth import AuthManager
2
- from .decorators import require_auth
3
-
4
- __version__ = "0.1.0"
1
+ from .auth import AuthManager
2
+ from .decorators import require_auth
3
+
4
+ __version__ = "0.1.0"
5
5
  __all__ = ["AuthManager", "require_auth"]