login512-fastapi 2.1.1__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.
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: login512-fastapi
3
+ Version: 2.1.1
4
+ Summary: FastAPI Security Dependency for Login512 Post-Quantum Biometrics and Passkeys
5
+ Home-page: https://login512.com
6
+ Author: Login512 Team
7
+ Author-email: support@login512.com
8
+ License: Apache-2.0
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: fastapi>=0.100.0
14
+ Requires-Dist: httpx>=0.24.0
15
+ Dynamic: author
16
+ Dynamic: author-email
17
+ Dynamic: classifier
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: requires-dist
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ # login512-fastapi
27
+
28
+ FastAPI Security Dependency for **Login512** Post-Quantum Biometrics and Passkeys.
29
+
30
+ ## Installation
31
+ ```bash
32
+ pip install login512-fastapi
33
+ ```
34
+
35
+ ## Usage
36
+ ```python
37
+ import os
38
+ from fastapi import FastAPI, Depends
39
+ from login512_fastapi import Login512Bearer
40
+
41
+ app = FastAPI()
42
+ auth_guard = Login512Bearer(secret_key=os.environ["LOGIN512_SECRET_KEY"])
43
+
44
+ @app.get("/api/user/profile")
45
+ async def get_user_profile(user_claims: dict = Depends(auth_guard)):
46
+ return {
47
+ "status": "authenticated",
48
+ "user_id": user_claims.get("sub"),
49
+ "mode": user_claims.get("mod"),
50
+ "risk": user_claims.get("risk"),
51
+ }
52
+ ```
53
+
@@ -0,0 +1,5 @@
1
+ login512_fastapi.py,sha256=kYJkakHEIPoq5QulV00q2D-qwMjLq8j8Tn_bWC1U3-c,2696
2
+ login512_fastapi-2.1.1.dist-info/METADATA,sha256=fWNUoVllhVQ1xdymCGIGfFIbTOWRb0tt6vUVDC6gN-g,1405
3
+ login512_fastapi-2.1.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
4
+ login512_fastapi-2.1.1.dist-info/top_level.txt,sha256=9lcM8oBm5yY8ydGslDXDWuDrbLQFGKyQfsXrtQrBZkw,17
5
+ login512_fastapi-2.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ login512_fastapi
login512_fastapi.py ADDED
@@ -0,0 +1,70 @@
1
+ """
2
+ login512_fastapi — FastAPI Security Dependency for Login512 Post-Quantum Biometrics
3
+ """
4
+
5
+ from __future__ import annotations
6
+ from typing import Any, Optional
7
+
8
+ from fastapi import Depends, HTTPException, Request, status
9
+ from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
10
+
11
+ import httpx
12
+
13
+ _security = HTTPBearer(auto_error=False)
14
+
15
+
16
+ class Login512Bearer:
17
+ """FastAPI Security Dependency that validates Login512 ML-DSA tokens."""
18
+
19
+ def __init__(self, secret_key: str, endpoint: str = "https://api.login512.com"):
20
+ if not secret_key.startswith("l512_sk_"):
21
+ raise ValueError("Invalid secret_key: must start with 'l512_sk_'")
22
+ self.secret_key = secret_key
23
+ self.endpoint = endpoint.rstrip("/")
24
+
25
+ async def __call__(
26
+ self,
27
+ credentials: Optional[HTTPAuthorizationCredentials] = Depends(_security),
28
+ ) -> dict[str, Any]:
29
+ if not credentials or not credentials.credentials:
30
+ raise HTTPException(
31
+ status_code=status.HTTP_401_UNAUTHORIZED,
32
+ detail="Missing Bearer authentication token",
33
+ headers={"WWW-Authenticate": "Bearer"},
34
+ )
35
+
36
+ token = credentials.credentials.strip()
37
+ try:
38
+ async with httpx.AsyncClient(timeout=5.0) as client:
39
+ res = await client.post(
40
+ f"{self.endpoint}/v1/token/verify",
41
+ headers={"Authorization": f"Bearer {self.secret_key}"},
42
+ json={"token": token},
43
+ )
44
+
45
+ if res.status_code != 200:
46
+ raise HTTPException(
47
+ status_code=status.HTTP_401_UNAUTHORIZED,
48
+ detail="Invalid or expired Login512 biometric token",
49
+ headers={"WWW-Authenticate": "Bearer"},
50
+ )
51
+
52
+ data = res.json()
53
+ if data.get("valid") is not True:
54
+ raise HTTPException(
55
+ status_code=status.HTTP_401_UNAUTHORIZED,
56
+ detail=data.get("error", "Biometric token verification failed"),
57
+ headers={"WWW-Authenticate": "Bearer"},
58
+ )
59
+ if data.get("step_up_required") is True:
60
+ raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="STEP_UP_REQUIRED")
61
+
62
+ return data.get("claims", {})
63
+ except HTTPException:
64
+ raise
65
+ except Exception as e:
66
+ raise HTTPException(
67
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
68
+ detail=f"Verification gateway error: {str(e)}",
69
+ )
70
+