Flask-Login512 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,51 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
from flask import request, jsonify, g, current_app
|
|
3
|
+
import httpx
|
|
4
|
+
|
|
5
|
+
class Login512:
|
|
6
|
+
def __init__(self, app=None):
|
|
7
|
+
if app is not None:
|
|
8
|
+
self.init_app(app)
|
|
9
|
+
|
|
10
|
+
def init_app(self, app):
|
|
11
|
+
app.config.setdefault("LOGIN512_ENDPOINT", "https://api.login512.com")
|
|
12
|
+
|
|
13
|
+
def login512_required(f):
|
|
14
|
+
@wraps(f)
|
|
15
|
+
def decorated_function(*args, **kwargs):
|
|
16
|
+
auth_header = request.headers.get("Authorization")
|
|
17
|
+
if not auth_header or not auth_header.startswith("Bearer "):
|
|
18
|
+
return jsonify({"error": "Missing or malformed Authorization header"}), 401
|
|
19
|
+
|
|
20
|
+
token = auth_header.split(" ", 1)[1]
|
|
21
|
+
secret_key = current_app.config.get("LOGIN512_SECRET_KEY")
|
|
22
|
+
endpoint = current_app.config.get("LOGIN512_ENDPOINT", "https://api.login512.com").rstrip("/")
|
|
23
|
+
|
|
24
|
+
if not secret_key:
|
|
25
|
+
return jsonify({"error": "LOGIN512_SECRET_KEY is not configured"}), 500
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
with httpx.Client(timeout=8.0) as client:
|
|
29
|
+
res = client.post(
|
|
30
|
+
f"{endpoint}/v1/token/verify",
|
|
31
|
+
headers={"Authorization": f"Bearer {secret_key}"},
|
|
32
|
+
json={"token": token}
|
|
33
|
+
)
|
|
34
|
+
data = res.json()
|
|
35
|
+
if res.status_code != 200 or data.get("valid") is not True:
|
|
36
|
+
# The API sends "error" as a code string for rejected tokens (200 + valid:false) and as an
|
|
37
|
+
# object {"code","message"} for HTTP errors.
|
|
38
|
+
err = data.get("error")
|
|
39
|
+
if isinstance(err, dict):
|
|
40
|
+
err = err.get("message") or err.get("code")
|
|
41
|
+
return jsonify({"error": err or "Invalid token"}), 401
|
|
42
|
+
if data.get("step_up_required") is True:
|
|
43
|
+
return jsonify({"error": "STEP_UP_REQUIRED"}), 401
|
|
44
|
+
|
|
45
|
+
g.login512_user = data.get("claims")
|
|
46
|
+
except Exception as e:
|
|
47
|
+
return jsonify({"error": str(e)}), 401
|
|
48
|
+
|
|
49
|
+
return f(*args, **kwargs)
|
|
50
|
+
return decorated_function
|
|
51
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Flask-Login512
|
|
3
|
+
Version: 2.1.1
|
|
4
|
+
Summary: Flask extension for Login512 Post-Quantum Biometrics and Passkeys
|
|
5
|
+
Home-page: https://login512.com
|
|
6
|
+
Author: Login512 Team
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: Flask>=2.0
|
|
14
|
+
Requires-Dist: httpx>=0.25.0
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: home-page
|
|
20
|
+
Dynamic: license
|
|
21
|
+
Dynamic: requires-dist
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
# Flask-Login512
|
|
26
|
+
|
|
27
|
+
Official Flask extension and `@login512_required` decorator for **Login512** Zero-Image Post-Quantum Biometrics and Passkeys.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install Flask-Login512
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from flask import Flask, jsonify, g
|
|
39
|
+
from flask_login512 import Login512, login512_required
|
|
40
|
+
|
|
41
|
+
app = Flask(__name__)
|
|
42
|
+
app.config["LOGIN512_SECRET_KEY"] = "l512_sk_your_key"
|
|
43
|
+
Login512(app)
|
|
44
|
+
|
|
45
|
+
@app.route("/api/profile")
|
|
46
|
+
@login512_required
|
|
47
|
+
def profile():
|
|
48
|
+
return jsonify({"user": g.login512_user})
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
app.run()
|
|
52
|
+
```
|
|
53
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
flask_login512/__init__.py,sha256=zlEgU8dSRt9NeuQlh9kYlxwyLENYeS7l6dYyFSKbU3Y,2126
|
|
2
|
+
flask_login512-2.1.1.dist-info/METADATA,sha256=c7QvXIont_YLl7V9EmiZdH5ifxeXPYv0YBSaFkuyq8c,1295
|
|
3
|
+
flask_login512-2.1.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
flask_login512-2.1.1.dist-info/top_level.txt,sha256=8unOmN46wT3NxuWzW9wsRJ_SLDxBBsrwKdX97WkLzlA,15
|
|
5
|
+
flask_login512-2.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flask_login512
|