u2auth 0.2.2__tar.gz → 0.4.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.
- {u2auth-0.2.2/u2auth.egg-info → u2auth-0.4.0}/PKG-INFO +43 -2
- {u2auth-0.2.2 → u2auth-0.4.0}/README.md +42 -1
- {u2auth-0.2.2 → u2auth-0.4.0}/pyproject.toml +1 -1
- {u2auth-0.2.2 → u2auth-0.4.0}/tests/test_client.py +135 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth/client.py +36 -0
- {u2auth-0.2.2 → u2auth-0.4.0/u2auth.egg-info}/PKG-INFO +43 -2
- {u2auth-0.2.2 → u2auth-0.4.0}/LICENSE +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/setup.cfg +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/tests/test_helpers.py +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/tests/test_totp.py +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/tests/test_webhook.py +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth/__init__.py +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth/helpers.py +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth/py.typed +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth/webhook.py +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth.egg-info/SOURCES.txt +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth.egg-info/dependency_links.txt +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth.egg-info/requires.txt +0 -0
- {u2auth-0.2.2 → u2auth-0.4.0}/u2auth.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: u2auth
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: U2Auth SDK for Python — TOTP verification, push approvals, and local TOTP helpers
|
|
5
5
|
Author-email: DollarMates Dev <dev@dollarmates.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -134,7 +134,7 @@ Sync API client. `base_url` defaults to `https://auth.u2secured.com`.
|
|
|
134
134
|
|
|
135
135
|
Calls `POST /api/v1/sdk/totp/verify`. Returns `{"valid": bool}`.
|
|
136
136
|
|
|
137
|
-
### `client.request_push(user_identifier, context, *, webhook_url?, ttl?, idempotency_key?) -> dict`
|
|
137
|
+
### `client.request_push(user_identifier, context, *, webhook_url?, ttl?, idempotency_key?, end_user_ip?) -> dict`
|
|
138
138
|
|
|
139
139
|
Calls `POST /api/v1/sdk/push/request`. Returns `{approval_id, status, expires_at}`.
|
|
140
140
|
|
|
@@ -164,6 +164,25 @@ The SDK never generates this key for you — a key invented per call would not
|
|
|
164
164
|
be stable across a retry, so derive it from whatever identifies the attempt
|
|
165
165
|
in your own system (e.g. a nonce rendered into the login form).
|
|
166
166
|
|
|
167
|
+
Pass `end_user_ip` — the address of the person signing in, as your server saw
|
|
168
|
+
it — for the new-country risk check (`new_country` and the new-country
|
|
169
|
+
policy). Leave it out and the check sees your server's address instead, as it
|
|
170
|
+
did before this option existed. It is sent only when given.
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
# Flask: request.remote_addr is the real client only if your proxies are
|
|
174
|
+
# configured (e.g. werkzeug's ProxyFix with the right hop count).
|
|
175
|
+
push = client.request_push(user.id, "Login from Chrome", end_user_ip=request.remote_addr)
|
|
176
|
+
|
|
177
|
+
# Django: request.META["REMOTE_ADDR"], under the same proxy caveat.
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Pass the real client IP. Behind a load balancer or reverse proxy, take the
|
|
181
|
+
address your trusted proxy configuration resolves, never a raw
|
|
182
|
+
`X-Forwarded-For` header — the browser can set that to anything. A value that
|
|
183
|
+
is not an IPv4/IPv6 address (`host:port` is accepted) raises `U2AuthError`
|
|
184
|
+
with code `INVALID_END_USER_IP`.
|
|
185
|
+
|
|
167
186
|
### `client.get_push_status(approval_id) -> dict`
|
|
168
187
|
|
|
169
188
|
Calls `GET /api/v1/sdk/push/{id}/status`. Returns `{approval_id, status}`.
|
|
@@ -215,6 +234,28 @@ while True:
|
|
|
215
234
|
cursor = page["next_cursor"]
|
|
216
235
|
```
|
|
217
236
|
|
|
237
|
+
### `client.list_sign_in_log(*, limit=0, cursor="") -> dict`
|
|
238
|
+
|
|
239
|
+
Calls `GET /api/v1/sdk/sign-in-log`. Returns `{"items": [...], "next_cursor": "...", "has_more": bool}`, oldest first. `limit` defaults to 500 on the server (max 1000); `limit <= 0` is omitted, as is an empty `cursor`. Raises `U2AuthError` with code `INVALID_CURSOR` for a malformed cursor, or `MACHINE_KEY_NOT_ALLOWED` if called with a machine key — use an app key.
|
|
240
|
+
|
|
241
|
+
#### Export the sign-in log
|
|
242
|
+
|
|
243
|
+
Pull the log on a schedule: load your saved cursor, call `list_sign_in_log`, persist `next_cursor`, and repeat while `has_more` is true.
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
cursor = load_cursor() # "" on the first run
|
|
247
|
+
while True:
|
|
248
|
+
page = client.list_sign_in_log(limit=1000, cursor=cursor)
|
|
249
|
+
for ev in page["items"]:
|
|
250
|
+
store(ev)
|
|
251
|
+
cursor = page["next_cursor"]
|
|
252
|
+
save_cursor(cursor)
|
|
253
|
+
if not page["has_more"]:
|
|
254
|
+
break
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Notes: rows are served about 30 seconds after they are recorded, so a fresh sign-in may not appear immediately. An expired push and its machine report both appear as separate rows; they are related by `approval_id`.
|
|
258
|
+
|
|
218
259
|
### Helpers (no API call)
|
|
219
260
|
|
|
220
261
|
```python
|
|
@@ -111,7 +111,7 @@ Sync API client. `base_url` defaults to `https://auth.u2secured.com`.
|
|
|
111
111
|
|
|
112
112
|
Calls `POST /api/v1/sdk/totp/verify`. Returns `{"valid": bool}`.
|
|
113
113
|
|
|
114
|
-
### `client.request_push(user_identifier, context, *, webhook_url?, ttl?, idempotency_key?) -> dict`
|
|
114
|
+
### `client.request_push(user_identifier, context, *, webhook_url?, ttl?, idempotency_key?, end_user_ip?) -> dict`
|
|
115
115
|
|
|
116
116
|
Calls `POST /api/v1/sdk/push/request`. Returns `{approval_id, status, expires_at}`.
|
|
117
117
|
|
|
@@ -141,6 +141,25 @@ The SDK never generates this key for you — a key invented per call would not
|
|
|
141
141
|
be stable across a retry, so derive it from whatever identifies the attempt
|
|
142
142
|
in your own system (e.g. a nonce rendered into the login form).
|
|
143
143
|
|
|
144
|
+
Pass `end_user_ip` — the address of the person signing in, as your server saw
|
|
145
|
+
it — for the new-country risk check (`new_country` and the new-country
|
|
146
|
+
policy). Leave it out and the check sees your server's address instead, as it
|
|
147
|
+
did before this option existed. It is sent only when given.
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# Flask: request.remote_addr is the real client only if your proxies are
|
|
151
|
+
# configured (e.g. werkzeug's ProxyFix with the right hop count).
|
|
152
|
+
push = client.request_push(user.id, "Login from Chrome", end_user_ip=request.remote_addr)
|
|
153
|
+
|
|
154
|
+
# Django: request.META["REMOTE_ADDR"], under the same proxy caveat.
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Pass the real client IP. Behind a load balancer or reverse proxy, take the
|
|
158
|
+
address your trusted proxy configuration resolves, never a raw
|
|
159
|
+
`X-Forwarded-For` header — the browser can set that to anything. A value that
|
|
160
|
+
is not an IPv4/IPv6 address (`host:port` is accepted) raises `U2AuthError`
|
|
161
|
+
with code `INVALID_END_USER_IP`.
|
|
162
|
+
|
|
144
163
|
### `client.get_push_status(approval_id) -> dict`
|
|
145
164
|
|
|
146
165
|
Calls `GET /api/v1/sdk/push/{id}/status`. Returns `{approval_id, status}`.
|
|
@@ -192,6 +211,28 @@ while True:
|
|
|
192
211
|
cursor = page["next_cursor"]
|
|
193
212
|
```
|
|
194
213
|
|
|
214
|
+
### `client.list_sign_in_log(*, limit=0, cursor="") -> dict`
|
|
215
|
+
|
|
216
|
+
Calls `GET /api/v1/sdk/sign-in-log`. Returns `{"items": [...], "next_cursor": "...", "has_more": bool}`, oldest first. `limit` defaults to 500 on the server (max 1000); `limit <= 0` is omitted, as is an empty `cursor`. Raises `U2AuthError` with code `INVALID_CURSOR` for a malformed cursor, or `MACHINE_KEY_NOT_ALLOWED` if called with a machine key — use an app key.
|
|
217
|
+
|
|
218
|
+
#### Export the sign-in log
|
|
219
|
+
|
|
220
|
+
Pull the log on a schedule: load your saved cursor, call `list_sign_in_log`, persist `next_cursor`, and repeat while `has_more` is true.
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
cursor = load_cursor() # "" on the first run
|
|
224
|
+
while True:
|
|
225
|
+
page = client.list_sign_in_log(limit=1000, cursor=cursor)
|
|
226
|
+
for ev in page["items"]:
|
|
227
|
+
store(ev)
|
|
228
|
+
cursor = page["next_cursor"]
|
|
229
|
+
save_cursor(cursor)
|
|
230
|
+
if not page["has_more"]:
|
|
231
|
+
break
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Notes: rows are served about 30 seconds after they are recorded, so a fresh sign-in may not appear immediately. An expired push and its machine report both appear as separate rows; they are related by `approval_id`.
|
|
235
|
+
|
|
195
236
|
### Helpers (no API call)
|
|
196
237
|
|
|
197
238
|
```python
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "u2auth"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "U2Auth SDK for Python — TOTP verification, push approvals, and local TOTP helpers"
|
|
9
9
|
authors = [{ name = "DollarMates Dev", email = "dev@dollarmates.com" }]
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -273,6 +273,43 @@ class TestRequestPushIdempotency:
|
|
|
273
273
|
srv.stop()
|
|
274
274
|
|
|
275
275
|
|
|
276
|
+
class TestRequestPushEndUserIP:
|
|
277
|
+
def test_sends_end_user_ip_in_the_body(self):
|
|
278
|
+
capture = {}
|
|
279
|
+
srv = MockServer(
|
|
280
|
+
make_handler(201, {"approval_id": "apr_abc", "status": "pending"},
|
|
281
|
+
assert_path="/api/v1/sdk/push/request", capture=capture)
|
|
282
|
+
)
|
|
283
|
+
client = Client("rka_test", base_url=srv.url)
|
|
284
|
+
client.request_push("alice", "ctx", end_user_ip="203.0.113.42")
|
|
285
|
+
assert capture["body"]["end_user_ip"] == "203.0.113.42"
|
|
286
|
+
srv.stop()
|
|
287
|
+
|
|
288
|
+
def test_omits_end_user_ip_when_not_given(self):
|
|
289
|
+
# Absent, the server falls back to the connecting address; an empty
|
|
290
|
+
# string must not be sent in its place.
|
|
291
|
+
capture = {}
|
|
292
|
+
srv = MockServer(
|
|
293
|
+
make_handler(201, {"approval_id": "apr_abc", "status": "pending"},
|
|
294
|
+
capture=capture)
|
|
295
|
+
)
|
|
296
|
+
client = Client("rka_test", base_url=srv.url)
|
|
297
|
+
client.request_push("alice", "ctx")
|
|
298
|
+
assert "end_user_ip" not in capture["body"]
|
|
299
|
+
srv.stop()
|
|
300
|
+
|
|
301
|
+
def test_surfaces_an_invalid_end_user_ip_as_u2autherror(self):
|
|
302
|
+
srv = MockServer(
|
|
303
|
+
make_handler(400, {"error": {"code": "INVALID_END_USER_IP", "message": "bad ip"}})
|
|
304
|
+
)
|
|
305
|
+
client = Client("rka_test", base_url=srv.url)
|
|
306
|
+
with pytest.raises(U2AuthError) as exc:
|
|
307
|
+
client.request_push("alice", "ctx", end_user_ip="nope")
|
|
308
|
+
assert exc.value.code == "INVALID_END_USER_IP"
|
|
309
|
+
assert exc.value.status_code == 400
|
|
310
|
+
srv.stop()
|
|
311
|
+
|
|
312
|
+
|
|
276
313
|
class TestGetPushStatus:
|
|
277
314
|
def test_returns_status(self):
|
|
278
315
|
srv = MockServer(
|
|
@@ -605,6 +642,104 @@ class TestListEnrolmentEvents:
|
|
|
605
642
|
srv.stop()
|
|
606
643
|
|
|
607
644
|
|
|
645
|
+
class TestListSignInLog:
|
|
646
|
+
PATH = "/api/v1/sdk/sign-in-log"
|
|
647
|
+
|
|
648
|
+
def _srv(self, body=None, status=200, **kw):
|
|
649
|
+
return MockServer(
|
|
650
|
+
make_handler(
|
|
651
|
+
status,
|
|
652
|
+
body if body is not None else {"items": [], "next_cursor": "", "has_more": False},
|
|
653
|
+
assert_method="GET",
|
|
654
|
+
assert_path=self.PATH,
|
|
655
|
+
**kw,
|
|
656
|
+
)
|
|
657
|
+
)
|
|
658
|
+
|
|
659
|
+
def test_default_call_sends_auth_and_no_query(self):
|
|
660
|
+
srv = self._srv(assert_query={}, assert_auth="Bearer rka_test")
|
|
661
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log()
|
|
662
|
+
srv.stop()
|
|
663
|
+
|
|
664
|
+
def test_limit_and_cursor_included_when_given(self):
|
|
665
|
+
srv = self._srv(assert_query={"limit": "1000", "cursor": "abc"})
|
|
666
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log(limit=1000, cursor="abc")
|
|
667
|
+
srv.stop()
|
|
668
|
+
|
|
669
|
+
def test_zero_limit_is_omitted(self):
|
|
670
|
+
srv = self._srv(assert_query={})
|
|
671
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log(limit=0)
|
|
672
|
+
srv.stop()
|
|
673
|
+
|
|
674
|
+
def test_negative_limit_is_omitted(self):
|
|
675
|
+
srv = self._srv(assert_query={})
|
|
676
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log(limit=-1)
|
|
677
|
+
srv.stop()
|
|
678
|
+
|
|
679
|
+
def test_empty_cursor_is_omitted(self):
|
|
680
|
+
srv = self._srv(assert_query={"limit": "5"})
|
|
681
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log(limit=5, cursor="")
|
|
682
|
+
srv.stop()
|
|
683
|
+
|
|
684
|
+
def test_cursor_is_url_encoded(self):
|
|
685
|
+
raw = "a+b/c=d e&f"
|
|
686
|
+
srv = self._srv(assert_query={"cursor": raw})
|
|
687
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log(cursor=raw)
|
|
688
|
+
srv.stop()
|
|
689
|
+
|
|
690
|
+
def test_decodes_fleet_and_push_rows_preserving_nulls(self):
|
|
691
|
+
fleet = {
|
|
692
|
+
"id": "e1", "occurred_at": "2026-11-10T00:00:00Z",
|
|
693
|
+
"received_at": "2026-11-10T00:00:05Z", "user_identifier": "alice",
|
|
694
|
+
"local_login": "alice", "kind": "machine", "origin": "ssh",
|
|
695
|
+
"method": "push", "outcome": "approved", "reason": "ok",
|
|
696
|
+
"city": "Berlin", "region": "", "country": "DE", "new_country": True,
|
|
697
|
+
"source_ip": "203.0.113.9", "machine_id": "m1", "machine_name": "web-1",
|
|
698
|
+
"service": "sshd", "context": "login", "approval_id": "ap1",
|
|
699
|
+
"seq": 7, "gap_count": 0, "clock_skew_seconds": 2,
|
|
700
|
+
}
|
|
701
|
+
push = {
|
|
702
|
+
"id": "e2", "occurred_at": "2026-11-10T00:01:00Z",
|
|
703
|
+
"received_at": "2026-11-10T00:01:01Z", "user_identifier": "bob",
|
|
704
|
+
"local_login": None, "kind": "push", "origin": "app",
|
|
705
|
+
"method": "push", "outcome": "approved", "reason": None,
|
|
706
|
+
"city": None, "region": None, "country": None, "new_country": False,
|
|
707
|
+
"source_ip": None, "machine_id": None, "machine_name": None,
|
|
708
|
+
"service": None, "context": None, "approval_id": "ap2",
|
|
709
|
+
"seq": None, "gap_count": None, "clock_skew_seconds": None,
|
|
710
|
+
}
|
|
711
|
+
srv = self._srv({"items": [fleet, push], "next_cursor": "c2", "has_more": True})
|
|
712
|
+
result = Client("rka_test", base_url=srv.url).list_sign_in_log()
|
|
713
|
+
srv.stop()
|
|
714
|
+
assert result == {"items": [fleet, push], "next_cursor": "c2", "has_more": True}
|
|
715
|
+
assert result["items"][0]["machine_id"] == "m1"
|
|
716
|
+
assert result["items"][0]["region"] == ""
|
|
717
|
+
assert result["items"][1]["city"] is None
|
|
718
|
+
assert result["items"][1]["machine_id"] is None
|
|
719
|
+
assert result["has_more"] is True
|
|
720
|
+
|
|
721
|
+
def test_invalid_cursor_surfaces_code(self):
|
|
722
|
+
srv = self._srv(
|
|
723
|
+
{"error": {"code": "INVALID_CURSOR", "message": "bad cursor"}}, status=400
|
|
724
|
+
)
|
|
725
|
+
with pytest.raises(U2AuthError) as exc:
|
|
726
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log(cursor="zzz")
|
|
727
|
+
srv.stop()
|
|
728
|
+
assert exc.value.code == "INVALID_CURSOR"
|
|
729
|
+
assert exc.value.status_code == 400
|
|
730
|
+
|
|
731
|
+
def test_machine_key_not_allowed_surfaces_code(self):
|
|
732
|
+
srv = self._srv(
|
|
733
|
+
{"error": {"code": "MACHINE_KEY_NOT_ALLOWED", "message": "use an app key"}},
|
|
734
|
+
status=403,
|
|
735
|
+
)
|
|
736
|
+
with pytest.raises(U2AuthError) as exc:
|
|
737
|
+
Client("rka_test", base_url=srv.url).list_sign_in_log()
|
|
738
|
+
srv.stop()
|
|
739
|
+
assert exc.value.code == "MACHINE_KEY_NOT_ALLOWED"
|
|
740
|
+
assert exc.value.status_code == 403
|
|
741
|
+
|
|
742
|
+
|
|
608
743
|
class TestListEnrolmentsUserIdentifier:
|
|
609
744
|
def test_user_identifier_included_when_given(self):
|
|
610
745
|
srv = MockServer(
|
|
@@ -39,6 +39,7 @@ class Client:
|
|
|
39
39
|
webhook_url: Optional[str] = None,
|
|
40
40
|
ttl: Optional[int] = None,
|
|
41
41
|
idempotency_key: Optional[str] = None,
|
|
42
|
+
end_user_ip: Optional[str] = None,
|
|
42
43
|
) -> Dict[str, Any]:
|
|
43
44
|
"""Create a push approval request. Returns {approval_id, status, expires_at}.
|
|
44
45
|
|
|
@@ -59,6 +60,15 @@ class Client:
|
|
|
59
60
|
U2AuthError with code 'IDEMPOTENCY_KEY_REUSED'. A key longer than
|
|
60
61
|
255 characters raises U2AuthError with code
|
|
61
62
|
'INVALID_IDEMPOTENCY_KEY'.
|
|
63
|
+
|
|
64
|
+
Pass `end_user_ip` — the address of the person signing in, as YOUR
|
|
65
|
+
server saw it — for the new-country risk check. Without it the check
|
|
66
|
+
sees your server's address. It is sent as `end_user_ip` only when
|
|
67
|
+
given. Use the real client IP: behind a reverse proxy, the address
|
|
68
|
+
your trusted proxy configuration resolves, never a raw
|
|
69
|
+
X-Forwarded-For header the browser can forge. A value that is not an
|
|
70
|
+
IPv4/IPv6 address (host:port is accepted) raises U2AuthError with
|
|
71
|
+
code 'INVALID_END_USER_IP'.
|
|
62
72
|
"""
|
|
63
73
|
body: Dict[str, Any] = {
|
|
64
74
|
"user_identifier": user_identifier,
|
|
@@ -68,6 +78,8 @@ class Client:
|
|
|
68
78
|
body["webhook_url"] = webhook_url
|
|
69
79
|
if ttl is not None:
|
|
70
80
|
body["ttl"] = ttl
|
|
81
|
+
if end_user_ip:
|
|
82
|
+
body["end_user_ip"] = end_user_ip
|
|
71
83
|
headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
|
|
72
84
|
return self._post("/api/v1/sdk/push/request", body, headers)
|
|
73
85
|
|
|
@@ -239,6 +251,30 @@ class Client:
|
|
|
239
251
|
path = f"/api/v1/sdk/enrolments/{enrolment_path}/events"
|
|
240
252
|
return self._get(f"{path}?{query}" if query else path)
|
|
241
253
|
|
|
254
|
+
def list_sign_in_log(self, *, limit: int = 0, cursor: str = "") -> Dict[str, Any]:
|
|
255
|
+
"""Pull the app's sign-in log, oldest first.
|
|
256
|
+
|
|
257
|
+
limit <= 0 is treated as unset and omitted from the query (the server
|
|
258
|
+
default is 500, max 1000), same as an empty cursor.
|
|
259
|
+
|
|
260
|
+
cursor is opaque; pass back the previous page's next_cursor verbatim.
|
|
261
|
+
Rows are served about 30 seconds after they are recorded.
|
|
262
|
+
|
|
263
|
+
Raises U2AuthError with code 'INVALID_CURSOR' if cursor is malformed,
|
|
264
|
+
or 'MACHINE_KEY_NOT_ALLOWED' if called with a machine key (use an app
|
|
265
|
+
key).
|
|
266
|
+
|
|
267
|
+
Returns {'items': [...], 'next_cursor': '...', 'has_more': bool}.
|
|
268
|
+
"""
|
|
269
|
+
params: Dict[str, Any] = {}
|
|
270
|
+
if limit > 0:
|
|
271
|
+
params["limit"] = limit
|
|
272
|
+
if cursor:
|
|
273
|
+
params["cursor"] = cursor
|
|
274
|
+
query = urllib.parse.urlencode(params)
|
|
275
|
+
path = "/api/v1/sdk/sign-in-log"
|
|
276
|
+
return self._get(f"{path}?{query}" if query else path)
|
|
277
|
+
|
|
242
278
|
def _post(
|
|
243
279
|
self, path: str, body: Dict[str, Any], headers: Optional[Dict[str, str]] = None
|
|
244
280
|
) -> Dict[str, Any]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: u2auth
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: U2Auth SDK for Python — TOTP verification, push approvals, and local TOTP helpers
|
|
5
5
|
Author-email: DollarMates Dev <dev@dollarmates.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -134,7 +134,7 @@ Sync API client. `base_url` defaults to `https://auth.u2secured.com`.
|
|
|
134
134
|
|
|
135
135
|
Calls `POST /api/v1/sdk/totp/verify`. Returns `{"valid": bool}`.
|
|
136
136
|
|
|
137
|
-
### `client.request_push(user_identifier, context, *, webhook_url?, ttl?, idempotency_key?) -> dict`
|
|
137
|
+
### `client.request_push(user_identifier, context, *, webhook_url?, ttl?, idempotency_key?, end_user_ip?) -> dict`
|
|
138
138
|
|
|
139
139
|
Calls `POST /api/v1/sdk/push/request`. Returns `{approval_id, status, expires_at}`.
|
|
140
140
|
|
|
@@ -164,6 +164,25 @@ The SDK never generates this key for you — a key invented per call would not
|
|
|
164
164
|
be stable across a retry, so derive it from whatever identifies the attempt
|
|
165
165
|
in your own system (e.g. a nonce rendered into the login form).
|
|
166
166
|
|
|
167
|
+
Pass `end_user_ip` — the address of the person signing in, as your server saw
|
|
168
|
+
it — for the new-country risk check (`new_country` and the new-country
|
|
169
|
+
policy). Leave it out and the check sees your server's address instead, as it
|
|
170
|
+
did before this option existed. It is sent only when given.
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
# Flask: request.remote_addr is the real client only if your proxies are
|
|
174
|
+
# configured (e.g. werkzeug's ProxyFix with the right hop count).
|
|
175
|
+
push = client.request_push(user.id, "Login from Chrome", end_user_ip=request.remote_addr)
|
|
176
|
+
|
|
177
|
+
# Django: request.META["REMOTE_ADDR"], under the same proxy caveat.
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Pass the real client IP. Behind a load balancer or reverse proxy, take the
|
|
181
|
+
address your trusted proxy configuration resolves, never a raw
|
|
182
|
+
`X-Forwarded-For` header — the browser can set that to anything. A value that
|
|
183
|
+
is not an IPv4/IPv6 address (`host:port` is accepted) raises `U2AuthError`
|
|
184
|
+
with code `INVALID_END_USER_IP`.
|
|
185
|
+
|
|
167
186
|
### `client.get_push_status(approval_id) -> dict`
|
|
168
187
|
|
|
169
188
|
Calls `GET /api/v1/sdk/push/{id}/status`. Returns `{approval_id, status}`.
|
|
@@ -215,6 +234,28 @@ while True:
|
|
|
215
234
|
cursor = page["next_cursor"]
|
|
216
235
|
```
|
|
217
236
|
|
|
237
|
+
### `client.list_sign_in_log(*, limit=0, cursor="") -> dict`
|
|
238
|
+
|
|
239
|
+
Calls `GET /api/v1/sdk/sign-in-log`. Returns `{"items": [...], "next_cursor": "...", "has_more": bool}`, oldest first. `limit` defaults to 500 on the server (max 1000); `limit <= 0` is omitted, as is an empty `cursor`. Raises `U2AuthError` with code `INVALID_CURSOR` for a malformed cursor, or `MACHINE_KEY_NOT_ALLOWED` if called with a machine key — use an app key.
|
|
240
|
+
|
|
241
|
+
#### Export the sign-in log
|
|
242
|
+
|
|
243
|
+
Pull the log on a schedule: load your saved cursor, call `list_sign_in_log`, persist `next_cursor`, and repeat while `has_more` is true.
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
cursor = load_cursor() # "" on the first run
|
|
247
|
+
while True:
|
|
248
|
+
page = client.list_sign_in_log(limit=1000, cursor=cursor)
|
|
249
|
+
for ev in page["items"]:
|
|
250
|
+
store(ev)
|
|
251
|
+
cursor = page["next_cursor"]
|
|
252
|
+
save_cursor(cursor)
|
|
253
|
+
if not page["has_more"]:
|
|
254
|
+
break
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Notes: rows are served about 30 seconds after they are recorded, so a fresh sign-in may not appear immediately. An expired push and its machine report both appear as separate rows; they are related by `approval_id`.
|
|
258
|
+
|
|
218
259
|
### Helpers (no API call)
|
|
219
260
|
|
|
220
261
|
```python
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|