foxlogin 0.3.1__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.
- foxlogin-0.3.1/.github/workflows/ci.yml +16 -0
- foxlogin-0.3.1/.github/workflows/publish.yml +32 -0
- foxlogin-0.3.1/.gitignore +9 -0
- foxlogin-0.3.1/CHANGELOG.md +30 -0
- foxlogin-0.3.1/LICENSE +21 -0
- foxlogin-0.3.1/PKG-INFO +154 -0
- foxlogin-0.3.1/README.md +126 -0
- foxlogin-0.3.1/pyproject.toml +46 -0
- foxlogin-0.3.1/src/foxlogin/__init__.py +52 -0
- foxlogin-0.3.1/src/foxlogin/_http.py +105 -0
- foxlogin-0.3.1/src/foxlogin/async_client.py +260 -0
- foxlogin-0.3.1/src/foxlogin/client.py +302 -0
- foxlogin-0.3.1/src/foxlogin/errors.py +52 -0
- foxlogin-0.3.1/src/foxlogin/py.typed +0 -0
- foxlogin-0.3.1/src/foxlogin/server.py +296 -0
- foxlogin-0.3.1/src/foxlogin/storage.py +75 -0
- foxlogin-0.3.1/src/foxlogin/types.py +79 -0
- foxlogin-0.3.1/tests/__init__.py +0 -0
- foxlogin-0.3.1/tests/helpers.py +91 -0
- foxlogin-0.3.1/tests/test_admin.py +81 -0
- foxlogin-0.3.1/tests/test_async_client.py +133 -0
- foxlogin-0.3.1/tests/test_client.py +162 -0
- foxlogin-0.3.1/tests/test_server.py +118 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
strategy:
|
|
7
|
+
matrix:
|
|
8
|
+
python-version: ["3.9", "3.10", "3.11", "3.12"]
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- uses: actions/setup-python@v5
|
|
12
|
+
with:
|
|
13
|
+
python-version: ${{ matrix.python-version }}
|
|
14
|
+
- run: python -m pip install --upgrade pip
|
|
15
|
+
- run: pip install -e '.[dev]'
|
|
16
|
+
- run: pytest -q
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags: ["v*"]
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- uses: actions/setup-python@v5
|
|
12
|
+
with:
|
|
13
|
+
python-version: "3.12"
|
|
14
|
+
- run: pip install -e '.[dev]' build
|
|
15
|
+
- run: pytest -q
|
|
16
|
+
- run: python -m build
|
|
17
|
+
- uses: actions/upload-artifact@v4
|
|
18
|
+
with:
|
|
19
|
+
name: dist
|
|
20
|
+
path: dist/
|
|
21
|
+
pypi:
|
|
22
|
+
needs: build
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
environment: pypi
|
|
25
|
+
permissions:
|
|
26
|
+
id-token: write
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/download-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: dist
|
|
31
|
+
path: dist/
|
|
32
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.1 — 2026-12-02
|
|
4
|
+
|
|
5
|
+
- `FoxLoginAdmin` accepts per-application secret keys (`sk_live_…`) as well as organization API
|
|
6
|
+
keys (`fk_live_…`). Other keys raise `FoxLoginError` with code `invalid_api_key`. New
|
|
7
|
+
`secret_key=` keyword, same as `api_key=`.
|
|
8
|
+
|
|
9
|
+
## 0.3.0 — 2026-12-02
|
|
10
|
+
|
|
11
|
+
- **Breaking:** `sign_in()`, `verify_sign_up()`, `sign_in_with_code()` and
|
|
12
|
+
`confirm_password_reset()` now return a result dict —
|
|
13
|
+
`{"status": "signed_in", "user": User}` or `{"status": "mfa_required", "mfa_token": str}` —
|
|
14
|
+
instead of a `User` directly. Code that did `user = fox.sign_in(...)` must switch to
|
|
15
|
+
`result = fox.sign_in(...); user = result["user"]` after checking `result["status"]`.
|
|
16
|
+
- Two-factor authentication: when a sign-in-shaped call answers `mfa_required`, nothing is
|
|
17
|
+
stored; call `verify_mfa(mfa_token=..., code=...)` to finish it (`POST
|
|
18
|
+
/v1/client/sign_in/mfa`), which stores the session and returns the `User`.
|
|
19
|
+
- Passwordless sign-in: `send_sign_in_code(email=...)` and `sign_in_with_code(email=, code=)`.
|
|
20
|
+
- Password reset: `start_password_reset(email=...)` and
|
|
21
|
+
`confirm_password_reset(email=, code=, password=)`.
|
|
22
|
+
- All of the above are available on both `FoxLogin` and `AsyncFoxLogin`.
|
|
23
|
+
|
|
24
|
+
## 0.1.0 — 2026-12-02
|
|
25
|
+
|
|
26
|
+
- First release: `FoxLogin` (sync, `threading.Lock` single-flight refresh) and
|
|
27
|
+
`AsyncFoxLogin` (`asyncio.Lock` single-flight refresh) clients — sign-up with
|
|
28
|
+
email code, sign-in, rotating sessions, `get_token()`, `on_change()`.
|
|
29
|
+
- `verify_token()` — EdDSA (Ed25519) only, JWKS cache, injectable keys.
|
|
30
|
+
- `FoxLoginAdmin` — `applications` and `users` management API.
|
foxlogin-0.3.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 METANETSOFT
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
foxlogin-0.3.1/PKG-INFO
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: foxlogin
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: Fox Login SDK for Python: sign-up, sign-in, sessions, token verification and the Management API. User data stays in its own region (EU, TR).
|
|
5
|
+
Project-URL: Homepage, https://foxlogin.app
|
|
6
|
+
Project-URL: Repository, https://github.com/METANETSOFT/foxlogin-python
|
|
7
|
+
Project-URL: Issues, https://github.com/METANETSOFT/foxlogin-python/issues
|
|
8
|
+
Author: METANETSOFT
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: auth,authentication,data-residency,foxlogin,gdpr,jwt,kvkk,login
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: httpx>=0.24
|
|
23
|
+
Requires-Dist: pyjwt[crypto]>=2.4
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# foxlogin
|
|
30
|
+
|
|
31
|
+
Official Python SDK for [Fox Login](https://foxlogin.app): hosted login where each user's data
|
|
32
|
+
is stored in their own region (EU or Türkiye).
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
pip install foxlogin
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Python 3.9+. Fully typed (`py.typed`). Sync (`FoxLogin`, backed by `httpx.Client`) and async
|
|
39
|
+
(`AsyncFoxLogin`, backed by `httpx.AsyncClient`) clients.
|
|
40
|
+
|
|
41
|
+
## Client: sign users in
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from foxlogin import FoxLogin
|
|
45
|
+
|
|
46
|
+
# The region comes from the key: pk_live_tr_... talks to tr.auth.foxlogin.app.
|
|
47
|
+
fox = FoxLogin(publishable_key="pk_live_tr_...")
|
|
48
|
+
|
|
49
|
+
fox.sign_up(email=email, password=password, country="TR", name=name) # always "verification_sent"
|
|
50
|
+
fox.verify_sign_up(email=email, code=code) # 6-digit code from the email
|
|
51
|
+
|
|
52
|
+
result = fox.sign_in(email=email, password=password)
|
|
53
|
+
if result["status"] == "mfa_required":
|
|
54
|
+
code = input("Enter your 6-digit code: ")
|
|
55
|
+
user = fox.verify_mfa(mfa_token=result["mfa_token"], code=code)
|
|
56
|
+
else:
|
|
57
|
+
user = result["user"]
|
|
58
|
+
|
|
59
|
+
fox.on_change(lambda state: print(state["status"]))
|
|
60
|
+
|
|
61
|
+
# Send this to your backend; it refreshes itself before it expires.
|
|
62
|
+
token = fox.get_token()
|
|
63
|
+
|
|
64
|
+
fox.sign_out()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Passwordless sign-in and password reset follow the same `{"status": "signed_in" | "mfa_required"}`
|
|
68
|
+
shape:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
fox.send_sign_in_code(email=email) # always "code_sent"
|
|
72
|
+
result = fox.sign_in_with_code(email=email, code=code)
|
|
73
|
+
|
|
74
|
+
fox.start_password_reset(email=email) # always "code_sent"
|
|
75
|
+
result = fox.confirm_password_reset(email=email, code=code, password=new_password)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Sessions live in memory by default. Pass `storage=` with your own `SessionStorage` (`get`/`set`/
|
|
79
|
+
`remove`) to persist them — e.g. an encrypted file or keyring entry.
|
|
80
|
+
|
|
81
|
+
The same API is available as `asyncio`:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from foxlogin import AsyncFoxLogin
|
|
85
|
+
|
|
86
|
+
fox = AsyncFoxLogin(publishable_key="pk_live_tr_...")
|
|
87
|
+
result = await fox.sign_in(email=email, password=password)
|
|
88
|
+
if result["status"] == "mfa_required":
|
|
89
|
+
user = await fox.verify_mfa(mfa_token=result["mfa_token"], code=code)
|
|
90
|
+
token = await fox.get_token()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Server: check tokens and manage users
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from foxlogin import verify_token, FoxLoginAdmin
|
|
97
|
+
|
|
98
|
+
claims = verify_token(bearer_token, application_id="app_...")
|
|
99
|
+
# claims["sub"] = user id, claims["rgn"] = "TR", claims["labels"] = {"store": "..."}
|
|
100
|
+
|
|
101
|
+
# A secret key (sk_live_...) belongs to one application. Copy it from the application's API keys tab.
|
|
102
|
+
admin = FoxLoginAdmin(secret_key=os.environ["FOXLOGIN_SECRET_KEY"])
|
|
103
|
+
user = admin.users.create("app_...", email="mehmet@anka.com.tr", country="TR")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
A secret key works only inside its own application, within the role you gave it (Full access,
|
|
107
|
+
Read and write users, Read only). For work across applications, such as creating a new
|
|
108
|
+
application, use an organization API key (`fk_live_...`, page "API keys" in the dashboard).
|
|
109
|
+
`api_key=` and `secret_key=` are the same option.
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
org = FoxLoginAdmin(api_key=os.environ["FOXLOGIN_API_KEY"])
|
|
113
|
+
app = org.applications.create(name="Anka Market", region="TR")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Keep both keys on your server. Never ship them to a browser or app.
|
|
117
|
+
|
|
118
|
+
`verify_token` accepts only EdDSA (Ed25519) tokens issued by `https://api.foxlogin.app`, caches
|
|
119
|
+
the public keys for an hour and refetches them once when it sees a new key id. Pass `keys=` to
|
|
120
|
+
verify offline against a fixed JWKS document (useful in tests).
|
|
121
|
+
|
|
122
|
+
### FastAPI middleware
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
126
|
+
from foxlogin import FoxLoginError, verify_token
|
|
127
|
+
|
|
128
|
+
app = FastAPI()
|
|
129
|
+
|
|
130
|
+
@app.middleware("http")
|
|
131
|
+
async def fox_login_auth(request: Request, call_next):
|
|
132
|
+
header = request.headers.get("authorization", "")
|
|
133
|
+
if header.startswith("Bearer "):
|
|
134
|
+
try:
|
|
135
|
+
request.state.claims = verify_token(header.removeprefix("Bearer "))
|
|
136
|
+
except FoxLoginError as exc:
|
|
137
|
+
raise HTTPException(status_code=401, detail=exc.code) from exc
|
|
138
|
+
return await call_next(request)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Errors
|
|
142
|
+
|
|
143
|
+
Every failure raises `FoxLoginError` with `status`, `code` (`invalid_credentials`,
|
|
144
|
+
`invalid_code`, `rate_limited`, `email_exists`, `country_not_allowed`, `invalid_token`,
|
|
145
|
+
`wrong_application`, ...), `message`, `retryable` and `retry_after` (seconds).
|
|
146
|
+
|
|
147
|
+
## Other languages
|
|
148
|
+
|
|
149
|
+
JavaScript/TypeScript, Go, PHP, Java, .NET, Ruby, Rust, Swift, Kotlin and Dart SDKs follow the
|
|
150
|
+
same contract: see [SDK-SPEC.md](../SDK-SPEC.md).
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT © METANETSOFT
|
foxlogin-0.3.1/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# foxlogin
|
|
2
|
+
|
|
3
|
+
Official Python SDK for [Fox Login](https://foxlogin.app): hosted login where each user's data
|
|
4
|
+
is stored in their own region (EU or Türkiye).
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
pip install foxlogin
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
Python 3.9+. Fully typed (`py.typed`). Sync (`FoxLogin`, backed by `httpx.Client`) and async
|
|
11
|
+
(`AsyncFoxLogin`, backed by `httpx.AsyncClient`) clients.
|
|
12
|
+
|
|
13
|
+
## Client: sign users in
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from foxlogin import FoxLogin
|
|
17
|
+
|
|
18
|
+
# The region comes from the key: pk_live_tr_... talks to tr.auth.foxlogin.app.
|
|
19
|
+
fox = FoxLogin(publishable_key="pk_live_tr_...")
|
|
20
|
+
|
|
21
|
+
fox.sign_up(email=email, password=password, country="TR", name=name) # always "verification_sent"
|
|
22
|
+
fox.verify_sign_up(email=email, code=code) # 6-digit code from the email
|
|
23
|
+
|
|
24
|
+
result = fox.sign_in(email=email, password=password)
|
|
25
|
+
if result["status"] == "mfa_required":
|
|
26
|
+
code = input("Enter your 6-digit code: ")
|
|
27
|
+
user = fox.verify_mfa(mfa_token=result["mfa_token"], code=code)
|
|
28
|
+
else:
|
|
29
|
+
user = result["user"]
|
|
30
|
+
|
|
31
|
+
fox.on_change(lambda state: print(state["status"]))
|
|
32
|
+
|
|
33
|
+
# Send this to your backend; it refreshes itself before it expires.
|
|
34
|
+
token = fox.get_token()
|
|
35
|
+
|
|
36
|
+
fox.sign_out()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Passwordless sign-in and password reset follow the same `{"status": "signed_in" | "mfa_required"}`
|
|
40
|
+
shape:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
fox.send_sign_in_code(email=email) # always "code_sent"
|
|
44
|
+
result = fox.sign_in_with_code(email=email, code=code)
|
|
45
|
+
|
|
46
|
+
fox.start_password_reset(email=email) # always "code_sent"
|
|
47
|
+
result = fox.confirm_password_reset(email=email, code=code, password=new_password)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Sessions live in memory by default. Pass `storage=` with your own `SessionStorage` (`get`/`set`/
|
|
51
|
+
`remove`) to persist them — e.g. an encrypted file or keyring entry.
|
|
52
|
+
|
|
53
|
+
The same API is available as `asyncio`:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from foxlogin import AsyncFoxLogin
|
|
57
|
+
|
|
58
|
+
fox = AsyncFoxLogin(publishable_key="pk_live_tr_...")
|
|
59
|
+
result = await fox.sign_in(email=email, password=password)
|
|
60
|
+
if result["status"] == "mfa_required":
|
|
61
|
+
user = await fox.verify_mfa(mfa_token=result["mfa_token"], code=code)
|
|
62
|
+
token = await fox.get_token()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Server: check tokens and manage users
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from foxlogin import verify_token, FoxLoginAdmin
|
|
69
|
+
|
|
70
|
+
claims = verify_token(bearer_token, application_id="app_...")
|
|
71
|
+
# claims["sub"] = user id, claims["rgn"] = "TR", claims["labels"] = {"store": "..."}
|
|
72
|
+
|
|
73
|
+
# A secret key (sk_live_...) belongs to one application. Copy it from the application's API keys tab.
|
|
74
|
+
admin = FoxLoginAdmin(secret_key=os.environ["FOXLOGIN_SECRET_KEY"])
|
|
75
|
+
user = admin.users.create("app_...", email="mehmet@anka.com.tr", country="TR")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
A secret key works only inside its own application, within the role you gave it (Full access,
|
|
79
|
+
Read and write users, Read only). For work across applications, such as creating a new
|
|
80
|
+
application, use an organization API key (`fk_live_...`, page "API keys" in the dashboard).
|
|
81
|
+
`api_key=` and `secret_key=` are the same option.
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
org = FoxLoginAdmin(api_key=os.environ["FOXLOGIN_API_KEY"])
|
|
85
|
+
app = org.applications.create(name="Anka Market", region="TR")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Keep both keys on your server. Never ship them to a browser or app.
|
|
89
|
+
|
|
90
|
+
`verify_token` accepts only EdDSA (Ed25519) tokens issued by `https://api.foxlogin.app`, caches
|
|
91
|
+
the public keys for an hour and refetches them once when it sees a new key id. Pass `keys=` to
|
|
92
|
+
verify offline against a fixed JWKS document (useful in tests).
|
|
93
|
+
|
|
94
|
+
### FastAPI middleware
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
98
|
+
from foxlogin import FoxLoginError, verify_token
|
|
99
|
+
|
|
100
|
+
app = FastAPI()
|
|
101
|
+
|
|
102
|
+
@app.middleware("http")
|
|
103
|
+
async def fox_login_auth(request: Request, call_next):
|
|
104
|
+
header = request.headers.get("authorization", "")
|
|
105
|
+
if header.startswith("Bearer "):
|
|
106
|
+
try:
|
|
107
|
+
request.state.claims = verify_token(header.removeprefix("Bearer "))
|
|
108
|
+
except FoxLoginError as exc:
|
|
109
|
+
raise HTTPException(status_code=401, detail=exc.code) from exc
|
|
110
|
+
return await call_next(request)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Errors
|
|
114
|
+
|
|
115
|
+
Every failure raises `FoxLoginError` with `status`, `code` (`invalid_credentials`,
|
|
116
|
+
`invalid_code`, `rate_limited`, `email_exists`, `country_not_allowed`, `invalid_token`,
|
|
117
|
+
`wrong_application`, ...), `message`, `retryable` and `retry_after` (seconds).
|
|
118
|
+
|
|
119
|
+
## Other languages
|
|
120
|
+
|
|
121
|
+
JavaScript/TypeScript, Go, PHP, Java, .NET, Ruby, Rust, Swift, Kotlin and Dart SDKs follow the
|
|
122
|
+
same contract: see [SDK-SPEC.md](../SDK-SPEC.md).
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT © METANETSOFT
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "foxlogin"
|
|
7
|
+
version = "0.3.1"
|
|
8
|
+
description = "Fox Login SDK for Python: sign-up, sign-in, sessions, token verification and the Management API. User data stays in its own region (EU, TR)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [{ name = "METANETSOFT" }]
|
|
13
|
+
keywords = ["auth", "authentication", "login", "jwt", "data-residency", "kvkk", "gdpr", "foxlogin"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.24",
|
|
27
|
+
"PyJWT[crypto]>=2.4",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=7",
|
|
33
|
+
"pytest-asyncio>=0.21",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://foxlogin.app"
|
|
38
|
+
Repository = "https://github.com/METANETSOFT/foxlogin-python"
|
|
39
|
+
Issues = "https://github.com/METANETSOFT/foxlogin-python/issues"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.wheel]
|
|
42
|
+
packages = ["src/foxlogin"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
asyncio_mode = "auto"
|
|
46
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Fox Login SDK: hosted login where each user's data is stored in their own
|
|
2
|
+
region (EU or Türkiye).
|
|
3
|
+
|
|
4
|
+
from foxlogin import FoxLogin
|
|
5
|
+
|
|
6
|
+
fox = FoxLogin(publishable_key="pk_live_tr_...")
|
|
7
|
+
fox.sign_up(email=email, password=password, country="TR")
|
|
8
|
+
|
|
9
|
+
Server-side helpers (``verify_token``, ``FoxLoginAdmin``) live in the same
|
|
10
|
+
package since this SDK targets a server-capable language.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from .async_client import AsyncFoxLogin
|
|
14
|
+
from .client import AuthState, FoxLogin, region_from_publishable_key
|
|
15
|
+
from .errors import FoxLoginError
|
|
16
|
+
from .server import ISSUER, FoxLoginAdmin, verify_token
|
|
17
|
+
from .storage import (
|
|
18
|
+
AsyncMemoryStorage,
|
|
19
|
+
AsyncSessionStorage,
|
|
20
|
+
MemoryStorage,
|
|
21
|
+
SessionStorage,
|
|
22
|
+
async_memory_storage,
|
|
23
|
+
memory_storage,
|
|
24
|
+
)
|
|
25
|
+
from .types import Application, MfaRequired, Session, SessionClaims, SignInResult, TokenPair, User
|
|
26
|
+
|
|
27
|
+
__version__ = "0.3.1"
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"__version__",
|
|
31
|
+
"FoxLogin",
|
|
32
|
+
"AsyncFoxLogin",
|
|
33
|
+
"AuthState",
|
|
34
|
+
"region_from_publishable_key",
|
|
35
|
+
"FoxLoginError",
|
|
36
|
+
"verify_token",
|
|
37
|
+
"FoxLoginAdmin",
|
|
38
|
+
"ISSUER",
|
|
39
|
+
"SessionStorage",
|
|
40
|
+
"AsyncSessionStorage",
|
|
41
|
+
"MemoryStorage",
|
|
42
|
+
"AsyncMemoryStorage",
|
|
43
|
+
"memory_storage",
|
|
44
|
+
"async_memory_storage",
|
|
45
|
+
"User",
|
|
46
|
+
"Session",
|
|
47
|
+
"TokenPair",
|
|
48
|
+
"SessionClaims",
|
|
49
|
+
"Application",
|
|
50
|
+
"MfaRequired",
|
|
51
|
+
"SignInResult",
|
|
52
|
+
]
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""JSON request helpers shared by the sync client, async client and admin
|
|
2
|
+
client. Not part of the public API."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any, Dict, Optional
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from .errors import FoxLoginError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _parse_error_body(response: httpx.Response) -> Dict[str, Any]:
|
|
14
|
+
try:
|
|
15
|
+
body = response.json()
|
|
16
|
+
except ValueError:
|
|
17
|
+
return {}
|
|
18
|
+
if isinstance(body, dict) and isinstance(body.get("error"), dict):
|
|
19
|
+
return body["error"]
|
|
20
|
+
return {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _retry_after(response: httpx.Response) -> Optional[float]:
|
|
24
|
+
value = response.headers.get("retry-after")
|
|
25
|
+
if value is None:
|
|
26
|
+
return None
|
|
27
|
+
try:
|
|
28
|
+
return float(value)
|
|
29
|
+
except ValueError:
|
|
30
|
+
return None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def raise_for_error(response: httpx.Response) -> None:
|
|
34
|
+
"""Raise :class:`FoxLoginError` for a non-2xx response; no-op otherwise."""
|
|
35
|
+
if 200 <= response.status_code < 300:
|
|
36
|
+
return
|
|
37
|
+
error = _parse_error_body(response)
|
|
38
|
+
code = error.get("code") if isinstance(error.get("code"), str) else "http_error"
|
|
39
|
+
message = (
|
|
40
|
+
error.get("message")
|
|
41
|
+
if isinstance(error.get("message"), str)
|
|
42
|
+
else f"HTTP {response.status_code}"
|
|
43
|
+
)
|
|
44
|
+
retryable = bool(error.get("retryable")) or response.status_code == 429 or response.status_code >= 500
|
|
45
|
+
region = error.get("region") if isinstance(error.get("region"), str) else None
|
|
46
|
+
details = error.get("details") if isinstance(error.get("details"), dict) else {}
|
|
47
|
+
raise FoxLoginError(
|
|
48
|
+
status=response.status_code,
|
|
49
|
+
code=code,
|
|
50
|
+
message=message,
|
|
51
|
+
retryable=retryable,
|
|
52
|
+
retry_after=_retry_after(response),
|
|
53
|
+
region=region,
|
|
54
|
+
details=details,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def parse_json_body(response: httpx.Response) -> Any:
|
|
59
|
+
if response.status_code == 204 or not response.content:
|
|
60
|
+
return None
|
|
61
|
+
try:
|
|
62
|
+
return response.json()
|
|
63
|
+
except ValueError:
|
|
64
|
+
return None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def network_error(cause: BaseException) -> FoxLoginError:
|
|
68
|
+
return FoxLoginError(
|
|
69
|
+
status=0,
|
|
70
|
+
code="network_error",
|
|
71
|
+
message=f"Could not reach Fox Login: {cause}",
|
|
72
|
+
retryable=True,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def request_sync(
|
|
77
|
+
client: httpx.Client,
|
|
78
|
+
method: str,
|
|
79
|
+
url: str,
|
|
80
|
+
*,
|
|
81
|
+
headers: Dict[str, str],
|
|
82
|
+
json_body: Any = None,
|
|
83
|
+
) -> Any:
|
|
84
|
+
try:
|
|
85
|
+
response = client.request(method, url, headers=headers, json=json_body)
|
|
86
|
+
except httpx.HTTPError as cause:
|
|
87
|
+
raise network_error(cause) from cause
|
|
88
|
+
raise_for_error(response)
|
|
89
|
+
return parse_json_body(response)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
async def request_async(
|
|
93
|
+
client: httpx.AsyncClient,
|
|
94
|
+
method: str,
|
|
95
|
+
url: str,
|
|
96
|
+
*,
|
|
97
|
+
headers: Dict[str, str],
|
|
98
|
+
json_body: Any = None,
|
|
99
|
+
) -> Any:
|
|
100
|
+
try:
|
|
101
|
+
response = await client.request(method, url, headers=headers, json=json_body)
|
|
102
|
+
except httpx.HTTPError as cause:
|
|
103
|
+
raise network_error(cause) from cause
|
|
104
|
+
raise_for_error(response)
|
|
105
|
+
return parse_json_body(response)
|