chdev 1.2.0__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.
chdev-1.2.0/PKG-INFO ADDED
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.4
2
+ Name: chdev
3
+ Version: 1.2.0
4
+ Summary: Official Python client library for chdev Authentication (SSO for Google, Discord, Microsoft)
5
+ Author-email: chdev <contact@chdev.co.uk>
6
+ Project-URL: Homepage, https://authentication.chdev.co.uk
7
+ Project-URL: Documentation, https://authentication.chdev.co.uk/devdocs/
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Security
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+
16
+ # chdev Python Library
17
+
18
+ Official Python client library for [chdev Authentication](https://authentication.chdev.co.uk). Seamless Single Sign-On (SSO) supporting **Google**, **Discord**, and **Microsoft** logins for CLI applications, automation scripts, and web frameworks.
19
+
20
+ Zero external dependencies — powered entirely by the Python standard library.
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install chdev
28
+ ```
29
+
30
+ *(You can also `import chdevauth` as a backward-compatible alias).*
31
+
32
+ ---
33
+
34
+ ## Quickstart
35
+
36
+ ### 1. Set Global Key & Sign In
37
+
38
+ ```python
39
+ import chdev
40
+
41
+ # Set your 50-character API secret key (or set CHDEV_AUTH_SECRET_KEY in your environment)
42
+ chdev.set_key("YOUR_50_CHAR_API_KEY")
43
+
44
+ # Interactive sign-in prompt (Google, Discord, or Microsoft)
45
+ user = chdev.prompt_login()
46
+
47
+ print("Logged in as:", user.name)
48
+ print("Email:", user.email)
49
+ print("User ID:", user.id)
50
+ print("Profile Picture:", user.pfp)
51
+ ```
52
+
53
+ Global variables are also injected directly:
54
+ ```python
55
+ import chdev
56
+
57
+ chdev.google_login("YOUR_KEY")
58
+ print(chdev.email, chdev.name)
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Authentication Providers
64
+
65
+ ```python
66
+ import chdev
67
+
68
+ # Google Sign-In
69
+ chdev.google_login("YOUR_KEY")
70
+
71
+ # Discord Sign-In
72
+ chdev.discord_login("YOUR_KEY")
73
+
74
+ # Microsoft Sign-In
75
+ chdev.microsoft_login("YOUR_KEY")
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Features
81
+
82
+ ### A. Interactive Menu (`prompt_login`)
83
+ ```python
84
+ import chdev
85
+
86
+ # Displays terminal choice: [1] Google, [2] Discord, [3] Microsoft
87
+ user = chdev.prompt_login("YOUR_KEY")
88
+ ```
89
+
90
+ ### B. Auth Decorator (`@require_auth`)
91
+ Protect any function so it only runs if the user is authenticated:
92
+ ```python
93
+ import chdev
94
+
95
+ chdev.set_key("YOUR_KEY")
96
+
97
+ @chdev.require_auth(provider="google")
98
+ def run_secure_task():
99
+ print(f"Executing task for {chdev.email}...")
100
+
101
+ run_secure_task()
102
+ ```
103
+
104
+ ### C. Backend Web Framework Helpers (`create_session` & `verify`)
105
+ For web apps (FastAPI, Flask, Django):
106
+ ```python
107
+ import chdev
108
+
109
+ chdev.set_key("YOUR_KEY")
110
+
111
+ # In your login route:
112
+ session_data = chdev.create_session(
113
+ return_url="https://myapp.com/auth/callback",
114
+ app_secret_code="my_secure_session_nonce",
115
+ provider="microsoft"
116
+ )
117
+ # Redirect user to session_data["login_url"]
118
+
119
+ # In your callback route:
120
+ verification = chdev.verify(
121
+ auth_token=request_token,
122
+ app_secret_code="my_secure_session_nonce"
123
+ )
124
+ if verification["valid"]:
125
+ user = verification["user"]
126
+ print("Verified user:", user["email"])
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Documentation & API Specification
132
+
133
+ Full API specification and guides are available at:
134
+ 👉 **[https://authentication.chdev.co.uk/devdocs/](https://authentication.chdev.co.uk/devdocs/)**
chdev-1.2.0/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # chdev Python Library
2
+
3
+ Official Python client library for [chdev Authentication](https://authentication.chdev.co.uk). Seamless Single Sign-On (SSO) supporting **Google**, **Discord**, and **Microsoft** logins for CLI applications, automation scripts, and web frameworks.
4
+
5
+ Zero external dependencies — powered entirely by the Python standard library.
6
+
7
+ ---
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install chdev
13
+ ```
14
+
15
+ *(You can also `import chdevauth` as a backward-compatible alias).*
16
+
17
+ ---
18
+
19
+ ## Quickstart
20
+
21
+ ### 1. Set Global Key & Sign In
22
+
23
+ ```python
24
+ import chdev
25
+
26
+ # Set your 50-character API secret key (or set CHDEV_AUTH_SECRET_KEY in your environment)
27
+ chdev.set_key("YOUR_50_CHAR_API_KEY")
28
+
29
+ # Interactive sign-in prompt (Google, Discord, or Microsoft)
30
+ user = chdev.prompt_login()
31
+
32
+ print("Logged in as:", user.name)
33
+ print("Email:", user.email)
34
+ print("User ID:", user.id)
35
+ print("Profile Picture:", user.pfp)
36
+ ```
37
+
38
+ Global variables are also injected directly:
39
+ ```python
40
+ import chdev
41
+
42
+ chdev.google_login("YOUR_KEY")
43
+ print(chdev.email, chdev.name)
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Authentication Providers
49
+
50
+ ```python
51
+ import chdev
52
+
53
+ # Google Sign-In
54
+ chdev.google_login("YOUR_KEY")
55
+
56
+ # Discord Sign-In
57
+ chdev.discord_login("YOUR_KEY")
58
+
59
+ # Microsoft Sign-In
60
+ chdev.microsoft_login("YOUR_KEY")
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Features
66
+
67
+ ### A. Interactive Menu (`prompt_login`)
68
+ ```python
69
+ import chdev
70
+
71
+ # Displays terminal choice: [1] Google, [2] Discord, [3] Microsoft
72
+ user = chdev.prompt_login("YOUR_KEY")
73
+ ```
74
+
75
+ ### B. Auth Decorator (`@require_auth`)
76
+ Protect any function so it only runs if the user is authenticated:
77
+ ```python
78
+ import chdev
79
+
80
+ chdev.set_key("YOUR_KEY")
81
+
82
+ @chdev.require_auth(provider="google")
83
+ def run_secure_task():
84
+ print(f"Executing task for {chdev.email}...")
85
+
86
+ run_secure_task()
87
+ ```
88
+
89
+ ### C. Backend Web Framework Helpers (`create_session` & `verify`)
90
+ For web apps (FastAPI, Flask, Django):
91
+ ```python
92
+ import chdev
93
+
94
+ chdev.set_key("YOUR_KEY")
95
+
96
+ # In your login route:
97
+ session_data = chdev.create_session(
98
+ return_url="https://myapp.com/auth/callback",
99
+ app_secret_code="my_secure_session_nonce",
100
+ provider="microsoft"
101
+ )
102
+ # Redirect user to session_data["login_url"]
103
+
104
+ # In your callback route:
105
+ verification = chdev.verify(
106
+ auth_token=request_token,
107
+ app_secret_code="my_secure_session_nonce"
108
+ )
109
+ if verification["valid"]:
110
+ user = verification["user"]
111
+ print("Verified user:", user["email"])
112
+ ```
113
+
114
+ ---
115
+
116
+ ## Documentation & API Specification
117
+
118
+ Full API specification and guides are available at:
119
+ 👉 **[https://authentication.chdev.co.uk/devdocs/](https://authentication.chdev.co.uk/devdocs/)**
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "chdev"
7
+ version = "1.2.0"
8
+ authors = [
9
+ { name="chdev", email="contact@chdev.co.uk" },
10
+ ]
11
+ description = "Official Python client library for chdev Authentication (SSO for Google, Discord, Microsoft)"
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: OS Independent",
18
+ "Topic :: Security",
19
+ "Topic :: Software Development :: Libraries :: Python Modules",
20
+ ]
21
+ dependencies = []
22
+
23
+ [project.urls]
24
+ "Homepage" = "https://authentication.chdev.co.uk"
25
+ "Documentation" = "https://authentication.chdev.co.uk/devdocs/"
26
+
27
+ [tool.setuptools.packages.find]
28
+ where = ["src"]
chdev-1.2.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,430 @@
1
+ from __future__ import annotations
2
+
3
+ import builtins
4
+ import functools
5
+ import json
6
+ import os
7
+ import sys
8
+ import time
9
+ import urllib.error
10
+ import urllib.request
11
+ import webbrowser
12
+ from typing import Any, Callable, Dict, Optional
13
+
14
+ __version__ = "1.2.0"
15
+ __all__ = [
16
+ "google_login",
17
+ "discord_login",
18
+ "microsoft_login",
19
+ "login",
20
+ "prompt_login",
21
+ "ask_login",
22
+ "require_auth",
23
+ "login_required",
24
+ "create_session",
25
+ "verify",
26
+ "set_key",
27
+ "api_key",
28
+ "email",
29
+ "pfp",
30
+ "picture",
31
+ "name",
32
+ "user",
33
+ "user_id",
34
+ "authenticated",
35
+ ]
36
+
37
+ BASE_URL = "https://authentication.chdev.co.uk"
38
+ AUTH_ENDPOINT = f"{BASE_URL}/api/cli-auth"
39
+
40
+ api_key: Optional[str] = None
41
+ email: Optional[str] = None
42
+ pfp: Optional[str] = None
43
+ picture: Optional[str] = None
44
+ name: Optional[str] = None
45
+ user_id: Optional[str] = None
46
+ user: Optional[Dict[str, Any]] = None
47
+ authenticated: bool = False
48
+
49
+
50
+ class AuthUser(str):
51
+ email: str
52
+ pfp: str
53
+ picture: str
54
+ name: str
55
+ id: str
56
+ user_id: str
57
+ provider: str
58
+ user: Dict[str, Any]
59
+
60
+ def __new__(cls, user_data: Dict[str, Any]):
61
+ user_email = user_data.get("email") or ""
62
+ obj = super().__new__(cls, user_email)
63
+ obj.email = user_email
64
+ obj.pfp = user_data.get("pfp") or user_data.get("picture") or ""
65
+ obj.picture = obj.pfp
66
+ obj.name = user_data.get("name") or ""
67
+ obj.id = str(user_data.get("id") or "")
68
+ obj.user_id = obj.id
69
+ obj.provider = user_data.get("provider") or "google"
70
+ obj.user = user_data
71
+ return obj
72
+
73
+ def __getitem__(self, item: Any) -> Any:
74
+ if isinstance(item, str):
75
+ return self.user.get(item)
76
+ return super().__getitem__(item)
77
+
78
+ def get(self, key: str, default: Any = None) -> Any:
79
+ return self.user.get(key, default)
80
+
81
+
82
+ def set_key(key: str) -> None:
83
+ """Set the global API key used for all chdev authentication requests."""
84
+ global api_key
85
+ k = (key or "").strip()
86
+ api_key = k
87
+ if k:
88
+ os.environ["CHDEV_AUTH_SECRET_KEY"] = k
89
+
90
+
91
+ def _get_key(key: Optional[str] = None) -> str:
92
+ k = (key or api_key or os.environ.get("CHDEV_AUTH_SECRET_KEY") or "").strip()
93
+ if not k:
94
+ sys.exit("Invalid key.")
95
+ return k
96
+
97
+
98
+ def _set_globals(res: Dict[str, Any]) -> AuthUser:
99
+ global email, pfp, picture, name, user, user_id, authenticated
100
+
101
+ user_data = res.get("user") or {}
102
+ auth_user = AuthUser(user_data)
103
+
104
+ user_email = auth_user.email
105
+ user_pfp = auth_user.pfp
106
+ user_name = auth_user.name
107
+ user_raw_id = auth_user.id
108
+
109
+ email = user_email
110
+ pfp = user_pfp
111
+ picture = user_pfp
112
+ name = user_name
113
+ user_id = user_raw_id
114
+ user = user_data
115
+ authenticated = True
116
+
117
+ try:
118
+ frame = sys._getframe(1)
119
+ while frame and frame.f_globals.get("__name__") in (__name__, "chdev", "chdevauth"):
120
+ frame = frame.f_back
121
+ if frame:
122
+ frame.f_globals["email"] = user_email
123
+ frame.f_globals["pfp"] = user_pfp
124
+ frame.f_globals["picture"] = user_pfp
125
+ frame.f_globals["name"] = user_name
126
+ frame.f_globals["user_id"] = user_raw_id
127
+ frame.f_globals["user"] = user_data
128
+ frame.f_globals["authenticated"] = True
129
+ except Exception:
130
+ pass
131
+
132
+ try:
133
+ builtins.email = user_email
134
+ builtins.pfp = user_pfp
135
+ builtins.picture = user_pfp
136
+ builtins.name = user_name
137
+ builtins.user_id = user_raw_id
138
+ builtins.user = user_data
139
+ builtins.authenticated = True
140
+ except Exception:
141
+ pass
142
+
143
+ return auth_user
144
+
145
+
146
+ def _post_json(
147
+ url: str,
148
+ payload: Dict[str, Any],
149
+ timeout: int = 15,
150
+ headers: Optional[Dict[str, str]] = None
151
+ ) -> Dict[str, Any]:
152
+ req_headers = {
153
+ "Content-Type": "application/json",
154
+ "User-Agent": "chdev-python/1.2.0"
155
+ }
156
+ if headers:
157
+ req_headers.update(headers)
158
+
159
+ req = urllib.request.Request(
160
+ url,
161
+ data=json.dumps(payload).encode("utf-8"),
162
+ headers=req_headers
163
+ )
164
+ try:
165
+ with urllib.request.urlopen(req, timeout=timeout) as resp:
166
+ return json.loads(resp.read().decode("utf-8"))
167
+ except urllib.error.HTTPError as e:
168
+ if e.code in (401, 403):
169
+ sys.exit("Invalid key.")
170
+ try:
171
+ err_body = json.loads(e.read().decode("utf-8"))
172
+ msg = err_body.get("message") or err_body.get("error") or f"HTTP {e.code}"
173
+ sys.exit(f"Request failed: {msg}")
174
+ except Exception:
175
+ sys.exit(f"Request failed ({e.code}).")
176
+ except urllib.error.URLError as e:
177
+ sys.exit(f"Connection error: {e.reason}")
178
+
179
+
180
+ def login(
181
+ key: Optional[str] = None,
182
+ provider: str = "google",
183
+ app_name: str = "Python Application",
184
+ open_browser: bool = True,
185
+ poll_interval: float = 1.0,
186
+ timeout: int = 300,
187
+ quiet: bool = False
188
+ ) -> AuthUser:
189
+ api_key_str = _get_key(key)
190
+
191
+ init_res = _post_json(AUTH_ENDPOINT, {
192
+ "action": "init",
193
+ "provider": provider,
194
+ "app_name": app_name,
195
+ "api_key": api_key_str
196
+ })
197
+
198
+ if init_res.get("status") != "success":
199
+ sys.exit(f"Failed to start authentication: {init_res.get('message', 'Unknown error')}")
200
+
201
+ session_id = init_res["session_id"]
202
+ app_secret_code = init_res["app_secret_code"]
203
+ login_url = init_res["login_url"]
204
+ if provider == "microsoft":
205
+ prov_label = "Microsoft"
206
+ elif provider == "discord":
207
+ prov_label = "Discord"
208
+ else:
209
+ prov_label = "Google"
210
+
211
+ if not quiet:
212
+ print(f"\nSign in with {prov_label}:")
213
+ print(f"{login_url}\n")
214
+
215
+ if open_browser:
216
+ try:
217
+ webbrowser.open(login_url)
218
+ if not quiet:
219
+ print("Browser opened. Waiting for authentication...")
220
+ except Exception:
221
+ if not quiet:
222
+ print("Please open the link above in your browser to sign in.")
223
+ elif not quiet:
224
+ print("Please open the link above in your browser to sign in.")
225
+
226
+ start_time = time.time()
227
+ while time.time() - start_time < timeout:
228
+ time.sleep(poll_interval)
229
+ try:
230
+ poll_res = _post_json(AUTH_ENDPOINT, {
231
+ "action": "poll",
232
+ "session_id": session_id,
233
+ "app_secret_code": app_secret_code,
234
+ "api_key": api_key_str
235
+ })
236
+ except Exception:
237
+ continue
238
+
239
+ if poll_res.get("status") == "success" and poll_res.get("completed"):
240
+ auth_user = _set_globals(poll_res)
241
+ if not quiet:
242
+ print(f"Successfully authenticated as {auth_user.email or auth_user.name}!\n")
243
+ return auth_user
244
+
245
+ if poll_res.get("status") == "expired":
246
+ sys.exit("Sign-in session has expired. Please try logging in again.")
247
+
248
+ sys.exit(f"Authentication timed out after {timeout} seconds.")
249
+
250
+
251
+ def google_login(
252
+ key: Optional[str] = None,
253
+ app_name: str = "Python Application",
254
+ open_browser: bool = True,
255
+ poll_interval: float = 1.0,
256
+ timeout: int = 300,
257
+ quiet: bool = False
258
+ ) -> AuthUser:
259
+ return login(
260
+ key=key,
261
+ provider="google",
262
+ app_name=app_name,
263
+ open_browser=open_browser,
264
+ poll_interval=poll_interval,
265
+ timeout=timeout,
266
+ quiet=quiet
267
+ )
268
+
269
+
270
+ def discord_login(
271
+ key: Optional[str] = None,
272
+ app_name: str = "Python Application",
273
+ open_browser: bool = True,
274
+ poll_interval: float = 1.0,
275
+ timeout: int = 300,
276
+ quiet: bool = False
277
+ ) -> AuthUser:
278
+ return login(
279
+ key=key,
280
+ provider="discord",
281
+ app_name=app_name,
282
+ open_browser=open_browser,
283
+ poll_interval=poll_interval,
284
+ timeout=timeout,
285
+ quiet=quiet
286
+ )
287
+
288
+
289
+ def microsoft_login(
290
+ key: Optional[str] = None,
291
+ app_name: str = "Python Application",
292
+ open_browser: bool = True,
293
+ poll_interval: float = 1.0,
294
+ timeout: int = 300,
295
+ quiet: bool = False
296
+ ) -> AuthUser:
297
+ return login(
298
+ key=key,
299
+ provider="microsoft",
300
+ app_name=app_name,
301
+ open_browser=open_browser,
302
+ poll_interval=poll_interval,
303
+ timeout=timeout,
304
+ quiet=quiet
305
+ )
306
+
307
+
308
+ def prompt_login(
309
+ key: Optional[str] = None,
310
+ app_name: str = "Python Application",
311
+ open_browser: bool = True,
312
+ poll_interval: float = 1.0,
313
+ timeout: int = 300,
314
+ quiet: bool = False
315
+ ) -> AuthUser:
316
+ """Interactively prompts the user to choose an authentication provider in the terminal."""
317
+ print("\nSelect Sign-In Provider:")
318
+ print(" [1] Google")
319
+ print(" [2] Discord")
320
+ print(" [3] Microsoft")
321
+ try:
322
+ raw_choice = input("Enter choice [1-3] (default: 1): ").strip().lower()
323
+ except (EOFError, KeyboardInterrupt):
324
+ sys.exit("\nAuthentication cancelled.")
325
+
326
+ if raw_choice in ("2", "discord"):
327
+ provider = "discord"
328
+ elif raw_choice in ("3", "microsoft", "ms"):
329
+ provider = "microsoft"
330
+ else:
331
+ provider = "google"
332
+
333
+ return login(
334
+ key=key,
335
+ provider=provider,
336
+ app_name=app_name,
337
+ open_browser=open_browser,
338
+ poll_interval=poll_interval,
339
+ timeout=timeout,
340
+ quiet=quiet
341
+ )
342
+
343
+
344
+ ask_login = prompt_login
345
+
346
+
347
+ def require_auth(
348
+ fn: Optional[Callable[..., Any]] = None,
349
+ *,
350
+ provider: str = "google",
351
+ app_name: str = "Python Application",
352
+ key: Optional[str] = None,
353
+ **login_kwargs: Any
354
+ ) -> Callable[..., Any]:
355
+ """Decorator ensuring that a function is only executed after successful authentication."""
356
+ def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
357
+ @functools.wraps(func)
358
+ def wrapper(*args: Any, **kwargs: Any) -> Any:
359
+ global authenticated
360
+ if not authenticated:
361
+ login(key=key, provider=provider, app_name=app_name, **login_kwargs)
362
+ return func(*args, **kwargs)
363
+ return wrapper
364
+
365
+ if fn is not None and callable(fn):
366
+ return decorator(fn)
367
+ return decorator
368
+
369
+
370
+ login_required = require_auth
371
+
372
+
373
+ def create_session(
374
+ return_url: str,
375
+ app_secret_code: str,
376
+ back_url: Optional[str] = None,
377
+ provider: str = "google",
378
+ app_name: Optional[str] = None,
379
+ app_icon: Optional[str] = None,
380
+ brand_color: Optional[str] = None,
381
+ app_id: Optional[str] = None,
382
+ key: Optional[str] = None,
383
+ timeout: int = 15
384
+ ) -> Dict[str, Any]:
385
+ """Backend helper to create an SSO session via POST /api/create-session."""
386
+ k = _get_key(key)
387
+ payload: Dict[str, Any] = {
388
+ "return_url": return_url,
389
+ "app_secret_code": app_secret_code,
390
+ "provider": provider,
391
+ "api_key": k
392
+ }
393
+ if back_url:
394
+ payload["back_url"] = back_url
395
+ if app_name:
396
+ payload["app_name"] = app_name
397
+ if app_icon:
398
+ payload["app_icon"] = app_icon
399
+ if brand_color:
400
+ payload["brand_color"] = brand_color
401
+ if app_id:
402
+ payload["app_id"] = app_id
403
+
404
+ return _post_json(
405
+ f"{BASE_URL}/api/create-session",
406
+ payload,
407
+ timeout=timeout,
408
+ headers={"X-API-Key": k}
409
+ )
410
+
411
+
412
+ def verify(
413
+ auth_token: str,
414
+ app_secret_code: str,
415
+ key: Optional[str] = None,
416
+ timeout: int = 15
417
+ ) -> Dict[str, Any]:
418
+ """Backend helper to verify an auth_token via POST /api/verify."""
419
+ k = _get_key(key)
420
+ payload = {
421
+ "auth_token": auth_token,
422
+ "app_secret_code": app_secret_code,
423
+ "api_key": k
424
+ }
425
+ return _post_json(
426
+ f"{BASE_URL}/api/verify",
427
+ payload,
428
+ timeout=timeout,
429
+ headers={"X-API-Key": k}
430
+ )
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.4
2
+ Name: chdev
3
+ Version: 1.2.0
4
+ Summary: Official Python client library for chdev Authentication (SSO for Google, Discord, Microsoft)
5
+ Author-email: chdev <contact@chdev.co.uk>
6
+ Project-URL: Homepage, https://authentication.chdev.co.uk
7
+ Project-URL: Documentation, https://authentication.chdev.co.uk/devdocs/
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Security
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+
16
+ # chdev Python Library
17
+
18
+ Official Python client library for [chdev Authentication](https://authentication.chdev.co.uk). Seamless Single Sign-On (SSO) supporting **Google**, **Discord**, and **Microsoft** logins for CLI applications, automation scripts, and web frameworks.
19
+
20
+ Zero external dependencies — powered entirely by the Python standard library.
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install chdev
28
+ ```
29
+
30
+ *(You can also `import chdevauth` as a backward-compatible alias).*
31
+
32
+ ---
33
+
34
+ ## Quickstart
35
+
36
+ ### 1. Set Global Key & Sign In
37
+
38
+ ```python
39
+ import chdev
40
+
41
+ # Set your 50-character API secret key (or set CHDEV_AUTH_SECRET_KEY in your environment)
42
+ chdev.set_key("YOUR_50_CHAR_API_KEY")
43
+
44
+ # Interactive sign-in prompt (Google, Discord, or Microsoft)
45
+ user = chdev.prompt_login()
46
+
47
+ print("Logged in as:", user.name)
48
+ print("Email:", user.email)
49
+ print("User ID:", user.id)
50
+ print("Profile Picture:", user.pfp)
51
+ ```
52
+
53
+ Global variables are also injected directly:
54
+ ```python
55
+ import chdev
56
+
57
+ chdev.google_login("YOUR_KEY")
58
+ print(chdev.email, chdev.name)
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Authentication Providers
64
+
65
+ ```python
66
+ import chdev
67
+
68
+ # Google Sign-In
69
+ chdev.google_login("YOUR_KEY")
70
+
71
+ # Discord Sign-In
72
+ chdev.discord_login("YOUR_KEY")
73
+
74
+ # Microsoft Sign-In
75
+ chdev.microsoft_login("YOUR_KEY")
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Features
81
+
82
+ ### A. Interactive Menu (`prompt_login`)
83
+ ```python
84
+ import chdev
85
+
86
+ # Displays terminal choice: [1] Google, [2] Discord, [3] Microsoft
87
+ user = chdev.prompt_login("YOUR_KEY")
88
+ ```
89
+
90
+ ### B. Auth Decorator (`@require_auth`)
91
+ Protect any function so it only runs if the user is authenticated:
92
+ ```python
93
+ import chdev
94
+
95
+ chdev.set_key("YOUR_KEY")
96
+
97
+ @chdev.require_auth(provider="google")
98
+ def run_secure_task():
99
+ print(f"Executing task for {chdev.email}...")
100
+
101
+ run_secure_task()
102
+ ```
103
+
104
+ ### C. Backend Web Framework Helpers (`create_session` & `verify`)
105
+ For web apps (FastAPI, Flask, Django):
106
+ ```python
107
+ import chdev
108
+
109
+ chdev.set_key("YOUR_KEY")
110
+
111
+ # In your login route:
112
+ session_data = chdev.create_session(
113
+ return_url="https://myapp.com/auth/callback",
114
+ app_secret_code="my_secure_session_nonce",
115
+ provider="microsoft"
116
+ )
117
+ # Redirect user to session_data["login_url"]
118
+
119
+ # In your callback route:
120
+ verification = chdev.verify(
121
+ auth_token=request_token,
122
+ app_secret_code="my_secure_session_nonce"
123
+ )
124
+ if verification["valid"]:
125
+ user = verification["user"]
126
+ print("Verified user:", user["email"])
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Documentation & API Specification
132
+
133
+ Full API specification and guides are available at:
134
+ 👉 **[https://authentication.chdev.co.uk/devdocs/](https://authentication.chdev.co.uk/devdocs/)**
@@ -0,0 +1,8 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/chdev/__init__.py
4
+ src/chdev.egg-info/PKG-INFO
5
+ src/chdev.egg-info/SOURCES.txt
6
+ src/chdev.egg-info/dependency_links.txt
7
+ src/chdev.egg-info/top_level.txt
8
+ src/chdevauth/__init__.py
@@ -0,0 +1,2 @@
1
+ chdev
2
+ chdevauth
@@ -0,0 +1,3 @@
1
+ """Backward-compatible chdevauth module redirecting to chdev."""
2
+ from chdev import *
3
+ from chdev import __version__, __all__