humanless-skyvern-bridge 0.1.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.
- humanless_skyvern_bridge-0.1.0/.gitignore +7 -0
- humanless_skyvern_bridge-0.1.0/Dockerfile +9 -0
- humanless_skyvern_bridge-0.1.0/LICENSE +21 -0
- humanless_skyvern_bridge-0.1.0/PKG-INFO +119 -0
- humanless_skyvern_bridge-0.1.0/README.md +96 -0
- humanless_skyvern_bridge-0.1.0/examples/run_skyvern_task.py +46 -0
- humanless_skyvern_bridge-0.1.0/pyproject.toml +50 -0
- humanless_skyvern_bridge-0.1.0/src/humanless_skyvern_bridge/__init__.py +6 -0
- humanless_skyvern_bridge-0.1.0/src/humanless_skyvern_bridge/__main__.py +17 -0
- humanless_skyvern_bridge-0.1.0/src/humanless_skyvern_bridge/app.py +198 -0
- humanless_skyvern_bridge-0.1.0/tests/__init__.py +0 -0
- humanless_skyvern_bridge-0.1.0/tests/test_contract.py +138 -0
- humanless_skyvern_bridge-0.1.0/tests/test_live.py +79 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ninety Nine Oranges
|
|
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.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: humanless-skyvern-bridge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Identity for AI agents: a Skyvern totp_url bridge backed by Humanless. It serves emailed OTP codes, magic links and authenticator (TOTP) codes to Skyvern tasks, for apps you own or are authorized to test.
|
|
5
|
+
Project-URL: Homepage, https://usehumanless.com
|
|
6
|
+
Project-URL: Documentation, https://usehumanless.com/docs
|
|
7
|
+
Project-URL: Source, https://github.com/usehumanless/integrations/tree/main/browser-agents/skyvern-bridge
|
|
8
|
+
Author-email: Ninety Nine Oranges <hello@usehumanless.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: 2fa,ai-agents,browser-agent,humanless,identity,identity for ai agents,otp,skyvern,totp,webhook
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Software Development :: Testing
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: httpx==0.29.0
|
|
19
|
+
Requires-Dist: humanless==0.1.1
|
|
20
|
+
Requires-Dist: starlette==1.10.0
|
|
21
|
+
Requires-Dist: uvicorn==0.55.0
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# humanless-skyvern-bridge
|
|
25
|
+
|
|
26
|
+
Identity for AI agents: a tiny HTTP service that implements [Skyvern](https://github.com/Skyvern-AI/skyvern)'s `totp_url` (2FA / verification
|
|
27
|
+
code webhook) contract on top of [Humanless](https://usehumanless.com). Point a Skyvern task or workflow at it and
|
|
28
|
+
Skyvern gets the code emailed to a Humanless inbox, a magic link, or the current code of an authenticator you
|
|
29
|
+
imported into Humanless, without you forwarding emails or storing TOTP secrets in Skyvern. For apps you own or are
|
|
30
|
+
authorized to test.
|
|
31
|
+
|
|
32
|
+
> **Use policy.** Use Humanless only for apps and accounts you own or are authorized to use or test. Never create
|
|
33
|
+
> bulk or fake accounts, and never use it to get around someone else's verification.
|
|
34
|
+
|
|
35
|
+
## Skyvern's contract (verified against skyvern 1.0.58 source)
|
|
36
|
+
|
|
37
|
+
From `skyvern/services/otp_service.py` (`poll_otp_value`, `_get_otp_value_from_url`) and
|
|
38
|
+
`skyvern/forge/sdk/core/security.py` (`generate_skyvern_webhook_signature`):
|
|
39
|
+
|
|
40
|
+
| | |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| when | while a run waits for a code: first poll after ~10 s, then every 10 s, for up to 15 min |
|
|
43
|
+
| request | `POST <totp_url>`, 30 s timeout, JSON body with any of `task_id`, `workflow_run_id`, `workflow_permanent_id` (compact `json.dumps`; **no `totp_identifier`**) |
|
|
44
|
+
| auth headers | `x-skyvern-timestamp` (unix s), `x-skyvern-signature` = hex HMAC-SHA256(raw body, key = your Skyvern API key) |
|
|
45
|
+
| answer | `200` + JSON object `{"verification_code": "123456"}`; empty / missing `verification_code` = "not yet, poll again"; strings over 10 chars (e.g. a link) are parsed by Skyvern's LLM step |
|
|
46
|
+
|
|
47
|
+
Because the body does not say *which* inbox, the bridge takes the Humanless ids from the URL path.
|
|
48
|
+
|
|
49
|
+
## Routes
|
|
50
|
+
|
|
51
|
+
| route | serves |
|
|
52
|
+
| --- | --- |
|
|
53
|
+
| `POST /skyvern/totp/email/{identity_id}` | next code emailed to that inbox (waits up to `BRIDGE_WAIT_SECONDS`, default 20, max 25) |
|
|
54
|
+
| `POST /skyvern/totp/email/{identity_id}?kind=link` | next magic link (`?kind=any`: code if the email has one, else the link) |
|
|
55
|
+
| `POST /skyvern/totp/authenticator/{identity_id}/{authenticator_id}` | current TOTP of an imported authenticator (waits out the last 3 s of a period) |
|
|
56
|
+
| `GET /healthz` | `{"ok": true}` |
|
|
57
|
+
|
|
58
|
+
Every POST must carry a valid Skyvern signature (checked with `SKYVERN_API_KEY`, timestamps older than 5 min are
|
|
59
|
+
rejected); otherwise `401` and Humanless is never called. Humanless errors and "nothing yet" return `200` with
|
|
60
|
+
`verification_code: null`, so Skyvern keeps polling instead of failing the run.
|
|
61
|
+
|
|
62
|
+
## Run it
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
uv sync
|
|
66
|
+
HUMANLESS_API_KEY=hl_live_... SKYVERN_API_KEY=sk_... uv run humanless-skyvern-bridge # :8787
|
|
67
|
+
# or
|
|
68
|
+
docker build -t humanless-skyvern-bridge . && docker run -p 8787:8787 -e HUMANLESS_API_KEY -e SKYVERN_API_KEY humanless-skyvern-bridge
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| env | |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `HUMANLESS_API_KEY` | required. Prefer a Humanless key scoped to the agent's identities with `read` + `totp` permissions |
|
|
74
|
+
| `SKYVERN_API_KEY` | required: verifies Skyvern's signature (`BRIDGE_ALLOW_UNSIGNED=1` only for local testing) |
|
|
75
|
+
| `BRIDGE_ALLOWED_IDENTITY_IDS` | optional comma-separated allowlist of Humanless identity ids |
|
|
76
|
+
| `BRIDGE_WAIT_SECONDS` | long-poll per Skyvern request (default 20, capped at 25 so we answer inside Skyvern's 30 s timeout) |
|
|
77
|
+
| `HOST` / `PORT` | default `0.0.0.0` / `8787` |
|
|
78
|
+
|
|
79
|
+
Skyvern Cloud rejects private hosts in `totp_url` (`validate_url` -> `is_blocked_host`), so expose the bridge on a
|
|
80
|
+
public HTTPS URL (a host, or a tunnel such as Cloudflare Tunnel) when you use Skyvern Cloud.
|
|
81
|
+
|
|
82
|
+
## Plug it into Skyvern
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from humanless import Humanless
|
|
86
|
+
from skyvern import Skyvern
|
|
87
|
+
|
|
88
|
+
with Humanless() as hl:
|
|
89
|
+
inbox = hl.create_identity(["email"])
|
|
90
|
+
run = await Skyvern(api_key=SKYVERN_API_KEY).run_task(
|
|
91
|
+
prompt=f"Sign up with {inbox['email']} and verify the email with the code you are sent.",
|
|
92
|
+
url="https://your-app.example.com/signup",
|
|
93
|
+
totp_url=f"https://bridge.example.com/skyvern/totp/email/{inbox['identity_id']}",
|
|
94
|
+
wait_for_completion=True,
|
|
95
|
+
)
|
|
96
|
+
hl.delete_identity(inbox["identity_id"])
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Workflows: set the block's / workflow's `totp_verification_url` to the same URL. For login 2FA on an account whose
|
|
100
|
+
authenticator you imported into Humanless (`POST /v1/identities/{id}/authenticators` with the `otpauth://` URI or
|
|
101
|
+
setup key), use `.../skyvern/totp/authenticator/{identity_id}/{authenticator_id}`.
|
|
102
|
+
|
|
103
|
+
Full example: [`examples/run_skyvern_task.py`](examples/run_skyvern_task.py)
|
|
104
|
+
(`uv run --with skyvern==1.0.58 python examples/run_skyvern_task.py`).
|
|
105
|
+
|
|
106
|
+
## Tests
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
uv run pytest # contract tests: requests built and signed exactly like skyvern 1.0.58, Humanless mocked
|
|
110
|
+
HUMANLESS_LIVE=1 HUMANLESS_API_KEY=... HUMANLESS_SANDBOX_KEY=... uv run pytest
|
|
111
|
+
# live: real Humanless; authenticator path (real key) + email path (sandbox + Acme demo)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Publish (not done yet)
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
uv build
|
|
118
|
+
uv publish # PyPI name: humanless-skyvern-bridge (available as of 2026-12-04)
|
|
119
|
+
```
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# humanless-skyvern-bridge
|
|
2
|
+
|
|
3
|
+
Identity for AI agents: a tiny HTTP service that implements [Skyvern](https://github.com/Skyvern-AI/skyvern)'s `totp_url` (2FA / verification
|
|
4
|
+
code webhook) contract on top of [Humanless](https://usehumanless.com). Point a Skyvern task or workflow at it and
|
|
5
|
+
Skyvern gets the code emailed to a Humanless inbox, a magic link, or the current code of an authenticator you
|
|
6
|
+
imported into Humanless, without you forwarding emails or storing TOTP secrets in Skyvern. For apps you own or are
|
|
7
|
+
authorized to test.
|
|
8
|
+
|
|
9
|
+
> **Use policy.** Use Humanless only for apps and accounts you own or are authorized to use or test. Never create
|
|
10
|
+
> bulk or fake accounts, and never use it to get around someone else's verification.
|
|
11
|
+
|
|
12
|
+
## Skyvern's contract (verified against skyvern 1.0.58 source)
|
|
13
|
+
|
|
14
|
+
From `skyvern/services/otp_service.py` (`poll_otp_value`, `_get_otp_value_from_url`) and
|
|
15
|
+
`skyvern/forge/sdk/core/security.py` (`generate_skyvern_webhook_signature`):
|
|
16
|
+
|
|
17
|
+
| | |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| when | while a run waits for a code: first poll after ~10 s, then every 10 s, for up to 15 min |
|
|
20
|
+
| request | `POST <totp_url>`, 30 s timeout, JSON body with any of `task_id`, `workflow_run_id`, `workflow_permanent_id` (compact `json.dumps`; **no `totp_identifier`**) |
|
|
21
|
+
| auth headers | `x-skyvern-timestamp` (unix s), `x-skyvern-signature` = hex HMAC-SHA256(raw body, key = your Skyvern API key) |
|
|
22
|
+
| answer | `200` + JSON object `{"verification_code": "123456"}`; empty / missing `verification_code` = "not yet, poll again"; strings over 10 chars (e.g. a link) are parsed by Skyvern's LLM step |
|
|
23
|
+
|
|
24
|
+
Because the body does not say *which* inbox, the bridge takes the Humanless ids from the URL path.
|
|
25
|
+
|
|
26
|
+
## Routes
|
|
27
|
+
|
|
28
|
+
| route | serves |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| `POST /skyvern/totp/email/{identity_id}` | next code emailed to that inbox (waits up to `BRIDGE_WAIT_SECONDS`, default 20, max 25) |
|
|
31
|
+
| `POST /skyvern/totp/email/{identity_id}?kind=link` | next magic link (`?kind=any`: code if the email has one, else the link) |
|
|
32
|
+
| `POST /skyvern/totp/authenticator/{identity_id}/{authenticator_id}` | current TOTP of an imported authenticator (waits out the last 3 s of a period) |
|
|
33
|
+
| `GET /healthz` | `{"ok": true}` |
|
|
34
|
+
|
|
35
|
+
Every POST must carry a valid Skyvern signature (checked with `SKYVERN_API_KEY`, timestamps older than 5 min are
|
|
36
|
+
rejected); otherwise `401` and Humanless is never called. Humanless errors and "nothing yet" return `200` with
|
|
37
|
+
`verification_code: null`, so Skyvern keeps polling instead of failing the run.
|
|
38
|
+
|
|
39
|
+
## Run it
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uv sync
|
|
43
|
+
HUMANLESS_API_KEY=hl_live_... SKYVERN_API_KEY=sk_... uv run humanless-skyvern-bridge # :8787
|
|
44
|
+
# or
|
|
45
|
+
docker build -t humanless-skyvern-bridge . && docker run -p 8787:8787 -e HUMANLESS_API_KEY -e SKYVERN_API_KEY humanless-skyvern-bridge
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| env | |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `HUMANLESS_API_KEY` | required. Prefer a Humanless key scoped to the agent's identities with `read` + `totp` permissions |
|
|
51
|
+
| `SKYVERN_API_KEY` | required: verifies Skyvern's signature (`BRIDGE_ALLOW_UNSIGNED=1` only for local testing) |
|
|
52
|
+
| `BRIDGE_ALLOWED_IDENTITY_IDS` | optional comma-separated allowlist of Humanless identity ids |
|
|
53
|
+
| `BRIDGE_WAIT_SECONDS` | long-poll per Skyvern request (default 20, capped at 25 so we answer inside Skyvern's 30 s timeout) |
|
|
54
|
+
| `HOST` / `PORT` | default `0.0.0.0` / `8787` |
|
|
55
|
+
|
|
56
|
+
Skyvern Cloud rejects private hosts in `totp_url` (`validate_url` -> `is_blocked_host`), so expose the bridge on a
|
|
57
|
+
public HTTPS URL (a host, or a tunnel such as Cloudflare Tunnel) when you use Skyvern Cloud.
|
|
58
|
+
|
|
59
|
+
## Plug it into Skyvern
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from humanless import Humanless
|
|
63
|
+
from skyvern import Skyvern
|
|
64
|
+
|
|
65
|
+
with Humanless() as hl:
|
|
66
|
+
inbox = hl.create_identity(["email"])
|
|
67
|
+
run = await Skyvern(api_key=SKYVERN_API_KEY).run_task(
|
|
68
|
+
prompt=f"Sign up with {inbox['email']} and verify the email with the code you are sent.",
|
|
69
|
+
url="https://your-app.example.com/signup",
|
|
70
|
+
totp_url=f"https://bridge.example.com/skyvern/totp/email/{inbox['identity_id']}",
|
|
71
|
+
wait_for_completion=True,
|
|
72
|
+
)
|
|
73
|
+
hl.delete_identity(inbox["identity_id"])
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Workflows: set the block's / workflow's `totp_verification_url` to the same URL. For login 2FA on an account whose
|
|
77
|
+
authenticator you imported into Humanless (`POST /v1/identities/{id}/authenticators` with the `otpauth://` URI or
|
|
78
|
+
setup key), use `.../skyvern/totp/authenticator/{identity_id}/{authenticator_id}`.
|
|
79
|
+
|
|
80
|
+
Full example: [`examples/run_skyvern_task.py`](examples/run_skyvern_task.py)
|
|
81
|
+
(`uv run --with skyvern==1.0.58 python examples/run_skyvern_task.py`).
|
|
82
|
+
|
|
83
|
+
## Tests
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
uv run pytest # contract tests: requests built and signed exactly like skyvern 1.0.58, Humanless mocked
|
|
87
|
+
HUMANLESS_LIVE=1 HUMANLESS_API_KEY=... HUMANLESS_SANDBOX_KEY=... uv run pytest
|
|
88
|
+
# live: real Humanless; authenticator path (real key) + email path (sandbox + Acme demo)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Publish (not done yet)
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
uv build
|
|
95
|
+
uv publish # PyPI name: humanless-skyvern-bridge (available as of 2026-12-04)
|
|
96
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Run a Skyvern task that signs up on the Acme demo app, getting the emailed code through the bridge.
|
|
2
|
+
|
|
3
|
+
# 1. run the bridge somewhere Skyvern can reach (Skyvern Cloud cannot call localhost: use a tunnel or a host)
|
|
4
|
+
HUMANLESS_API_KEY=... SKYVERN_API_KEY=... uv run humanless-skyvern-bridge
|
|
5
|
+
# 2. run this (needs the Skyvern SDK: uv run --with skyvern==1.0.58 python examples/run_skyvern_task.py)
|
|
6
|
+
BRIDGE_URL=https://your-bridge.example.com HUMANLESS_API_KEY=... SKYVERN_API_KEY=... python examples/run_skyvern_task.py
|
|
7
|
+
|
|
8
|
+
The demo app only mails sandbox inboxes: use a sandbox key (POST https://api.usehumanless.com/v1/sandbox/keys) as
|
|
9
|
+
HUMANLESS_API_KEY for both the bridge and this script. Use Humanless only for apps and accounts you own or are
|
|
10
|
+
authorized to use or test.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import asyncio
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
from humanless import Humanless
|
|
17
|
+
from skyvern import Skyvern
|
|
18
|
+
|
|
19
|
+
DEMO_URL = "https://api.usehumanless.com/demo/acme"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
async def main() -> None:
|
|
23
|
+
bridge = os.environ["BRIDGE_URL"].rstrip("/")
|
|
24
|
+
with Humanless() as hl: # HUMANLESS_API_KEY
|
|
25
|
+
inbox = hl.create_identity(["email"], ttl_seconds=3600)
|
|
26
|
+
try:
|
|
27
|
+
skyvern = Skyvern(api_key=os.environ["SKYVERN_API_KEY"])
|
|
28
|
+
run = await skyvern.run_task(
|
|
29
|
+
prompt=(
|
|
30
|
+
f"Create an Acme account with the email {inbox['email']}. When the site asks for the "
|
|
31
|
+
"verification code sent by email, enter it and verify the email. COMPLETE when the page says "
|
|
32
|
+
"'Turn on two-factor authentication' or 'Email verified'."
|
|
33
|
+
),
|
|
34
|
+
url=DEMO_URL,
|
|
35
|
+
# Skyvern POSTs here whenever it needs the code; the bridge waits for it in the Humanless inbox
|
|
36
|
+
totp_url=f"{bridge}/skyvern/totp/email/{inbox['identity_id']}",
|
|
37
|
+
wait_for_completion=True,
|
|
38
|
+
timeout=900,
|
|
39
|
+
)
|
|
40
|
+
print(run.status, run.output)
|
|
41
|
+
finally:
|
|
42
|
+
hl.delete_identity(inbox["identity_id"])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if __name__ == "__main__":
|
|
46
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling==1.33.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "humanless-skyvern-bridge"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Identity for AI agents: a Skyvern totp_url bridge backed by Humanless. It serves emailed OTP codes, magic links and authenticator (TOTP) codes to Skyvern tasks, for apps you own or are authorized to test."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [{ name = "Ninety Nine Oranges", email = "hello@usehumanless.com" }]
|
|
13
|
+
keywords = ["identity", "ai-agents", "identity for ai agents", "skyvern", "humanless", "totp", "otp", "2fa", "webhook", "browser-agent"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Framework :: AsyncIO",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Software Development :: Testing",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"humanless==0.1.1",
|
|
23
|
+
"httpx==0.29.0",
|
|
24
|
+
"starlette==1.10.0",
|
|
25
|
+
"uvicorn==0.55.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
humanless-skyvern-bridge = "humanless_skyvern_bridge.__main__:main"
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://usehumanless.com"
|
|
33
|
+
Documentation = "https://usehumanless.com/docs"
|
|
34
|
+
Source = "https://github.com/usehumanless/integrations/tree/main/browser-agents/skyvern-bridge"
|
|
35
|
+
|
|
36
|
+
[dependency-groups]
|
|
37
|
+
dev = ["pytest==9.2.0", "pytest-asyncio==1.5.0"]
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["src/humanless_skyvern_bridge"]
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.sdist]
|
|
43
|
+
include = ["src", "examples", "tests", "README.md", "LICENSE", "pyproject.toml", "Dockerfile"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
asyncio_mode = "auto"
|
|
48
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
49
|
+
markers = ["live: hits the real Humanless API (set HUMANLESS_LIVE=1)"]
|
|
50
|
+
filterwarnings = ["ignore:Using `httpx` with `starlette.testclient`"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""humanless-skyvern-bridge: run the bridge with uvicorn (HOST/PORT env, default 0.0.0.0:8787)."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
import uvicorn
|
|
7
|
+
|
|
8
|
+
from .app import create_app
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main() -> None:
|
|
12
|
+
logging.basicConfig(level=os.environ.get("LOG_LEVEL", "INFO"))
|
|
13
|
+
uvicorn.run(create_app(), host=os.environ.get("HOST", "0.0.0.0"), port=int(os.environ.get("PORT", "8787")))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
main()
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Skyvern ``totp_url`` (TOTP / 2FA webhook) bridge backed by Humanless.
|
|
2
|
+
|
|
3
|
+
Skyvern's contract (skyvern/services/otp_service.py, ``_get_otp_value_from_url``, skyvern 1.0.58):
|
|
4
|
+
|
|
5
|
+
* While a task or workflow is waiting for a 2FA / verification code, Skyvern POSTs to the ``totp_url`` you gave it
|
|
6
|
+
(``totp_verification_url`` on the API) about every 10 s, for up to 15 min, with a 30 s request timeout.
|
|
7
|
+
* Body (JSON, compact separators): any of ``{"task_id": ..., "workflow_run_id": ..., "workflow_permanent_id": ...}``.
|
|
8
|
+
The body does NOT carry ``totp_identifier``, so this bridge puts the Humanless ids in the URL path.
|
|
9
|
+
* Headers: ``x-skyvern-timestamp`` (unix seconds) and ``x-skyvern-signature`` = hex HMAC-SHA256 of the raw body,
|
|
10
|
+
keyed with your Skyvern API key (skyvern/forge/sdk/core/security.py, ``generate_skyvern_webhook_signature``).
|
|
11
|
+
* Expected answer: HTTP 200, JSON object ``{"verification_code": "123456"}``. A 200 with no / empty
|
|
12
|
+
``verification_code`` means "not yet": Skyvern polls again. A string longer than 10 chars (e.g. a magic link) is
|
|
13
|
+
parsed by Skyvern's LLM step into a code or link.
|
|
14
|
+
|
|
15
|
+
Routes:
|
|
16
|
+
|
|
17
|
+
* ``POST /skyvern/totp/email/{identity_id}`` - waits (up to BRIDGE_WAIT_SECONDS, default 20) for the next code
|
|
18
|
+
emailed to that Humanless inbox. ``?kind=link`` waits for a magic link instead, ``?kind=any`` for either.
|
|
19
|
+
* ``POST /skyvern/totp/authenticator/{identity_id}/{authenticator_id}`` - the current code of an authenticator
|
|
20
|
+
imported into Humanless (waits out the last 3 s of a period so the code is still valid when typed).
|
|
21
|
+
* ``GET /healthz``.
|
|
22
|
+
|
|
23
|
+
Use Humanless only for apps and accounts you own or are authorized to use or test.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
import asyncio
|
|
29
|
+
import hashlib
|
|
30
|
+
import hmac
|
|
31
|
+
import json
|
|
32
|
+
import logging
|
|
33
|
+
import os
|
|
34
|
+
import time
|
|
35
|
+
from contextlib import asynccontextmanager
|
|
36
|
+
from dataclasses import dataclass, field
|
|
37
|
+
from typing import Any, AsyncIterator, Callable, Optional
|
|
38
|
+
from urllib.parse import quote
|
|
39
|
+
|
|
40
|
+
import httpx
|
|
41
|
+
from humanless import AsyncHumanless, HumanlessError, HumanlessTimeoutError
|
|
42
|
+
from starlette.applications import Starlette
|
|
43
|
+
from starlette.requests import Request
|
|
44
|
+
from starlette.responses import JSONResponse
|
|
45
|
+
from starlette.routing import Route
|
|
46
|
+
|
|
47
|
+
log = logging.getLogger("humanless_skyvern_bridge")
|
|
48
|
+
|
|
49
|
+
# Skyvern's request timeout is 30 s (DEFAULT_REQUEST_TIMEOUT); answer well before it.
|
|
50
|
+
DEFAULT_WAIT_SECONDS = 20.0
|
|
51
|
+
MAX_WAIT_SECONDS = 25.0
|
|
52
|
+
SIGNATURE_MAX_AGE_SECONDS = 300
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass
|
|
56
|
+
class BridgeConfig:
|
|
57
|
+
humanless_api_key: str
|
|
58
|
+
#: Your Skyvern API key: verifies x-skyvern-signature. None only with allow_unsigned=True (local testing).
|
|
59
|
+
skyvern_api_key: Optional[str]
|
|
60
|
+
humanless_base_url: Optional[str] = None
|
|
61
|
+
wait_seconds: float = DEFAULT_WAIT_SECONDS
|
|
62
|
+
allow_unsigned: bool = False
|
|
63
|
+
#: If set, only these Humanless identity ids can be read through the bridge.
|
|
64
|
+
allowed_identity_ids: Optional[set[str]] = None
|
|
65
|
+
#: For tests: an httpx transport used for Humanless calls.
|
|
66
|
+
transport: Optional[httpx.AsyncBaseTransport] = None
|
|
67
|
+
clock: Callable[[], float] = field(default=time.time)
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def from_env(cls) -> "BridgeConfig":
|
|
71
|
+
key = os.environ.get("HUMANLESS_API_KEY")
|
|
72
|
+
if not key:
|
|
73
|
+
raise SystemExit("Set HUMANLESS_API_KEY (ideally an identity-scoped key with read + totp permissions)")
|
|
74
|
+
allow_unsigned = os.environ.get("BRIDGE_ALLOW_UNSIGNED") == "1"
|
|
75
|
+
sk = os.environ.get("SKYVERN_API_KEY")
|
|
76
|
+
if not sk and not allow_unsigned:
|
|
77
|
+
raise SystemExit("Set SKYVERN_API_KEY to verify Skyvern's signature (or BRIDGE_ALLOW_UNSIGNED=1 for local tests only)")
|
|
78
|
+
ids = os.environ.get("BRIDGE_ALLOWED_IDENTITY_IDS")
|
|
79
|
+
return cls(
|
|
80
|
+
humanless_api_key=key,
|
|
81
|
+
skyvern_api_key=sk,
|
|
82
|
+
humanless_base_url=os.environ.get("HUMANLESS_BASE_URL"),
|
|
83
|
+
wait_seconds=min(float(os.environ.get("BRIDGE_WAIT_SECONDS", DEFAULT_WAIT_SECONDS)), MAX_WAIT_SECONDS),
|
|
84
|
+
allow_unsigned=allow_unsigned,
|
|
85
|
+
allowed_identity_ids={i.strip() for i in ids.split(",") if i.strip()} if ids else None,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def skyvern_signature(body: bytes, api_key: str) -> str:
|
|
90
|
+
"""What Skyvern sends in x-skyvern-signature: hex HMAC-SHA256 of the raw request body, keyed with the API key."""
|
|
91
|
+
return hmac.new(api_key.encode("utf-8"), msg=body, digestmod=hashlib.sha256).hexdigest()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _verify(request_headers: Any, body: bytes, cfg: BridgeConfig) -> Optional[str]:
|
|
95
|
+
"""None when the request is authentic, else the reason it is not."""
|
|
96
|
+
if cfg.skyvern_api_key is None:
|
|
97
|
+
return None if cfg.allow_unsigned else "bridge has no SKYVERN_API_KEY"
|
|
98
|
+
sig = request_headers.get("x-skyvern-signature")
|
|
99
|
+
ts = request_headers.get("x-skyvern-timestamp")
|
|
100
|
+
if not sig or not ts:
|
|
101
|
+
return "missing x-skyvern-signature / x-skyvern-timestamp"
|
|
102
|
+
try:
|
|
103
|
+
age = abs(cfg.clock() - int(ts))
|
|
104
|
+
except ValueError:
|
|
105
|
+
return "bad x-skyvern-timestamp"
|
|
106
|
+
if age > SIGNATURE_MAX_AGE_SECONDS:
|
|
107
|
+
return "stale x-skyvern-timestamp"
|
|
108
|
+
if not hmac.compare_digest(sig, skyvern_signature(body, cfg.skyvern_api_key)):
|
|
109
|
+
return "bad x-skyvern-signature"
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _no_code_yet(reason: str) -> JSONResponse:
|
|
114
|
+
# 200 + JSON object without a code: Skyvern logs it and polls again in ~10 s (no failure counted).
|
|
115
|
+
return JSONResponse({"verification_code": None, "status": "pending", "detail": reason})
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def create_app(cfg: Optional[BridgeConfig] = None) -> Starlette:
|
|
119
|
+
cfg = cfg or BridgeConfig.from_env()
|
|
120
|
+
|
|
121
|
+
@asynccontextmanager
|
|
122
|
+
async def client() -> AsyncIterator[AsyncHumanless]:
|
|
123
|
+
async with httpx.AsyncClient(transport=cfg.transport) as http:
|
|
124
|
+
yield AsyncHumanless(cfg.humanless_api_key, base_url=cfg.humanless_base_url, http_client=http)
|
|
125
|
+
|
|
126
|
+
async def authenticate(request: Request) -> tuple[Optional[JSONResponse], dict]:
|
|
127
|
+
body = await request.body()
|
|
128
|
+
reason = _verify(request.headers, body, cfg)
|
|
129
|
+
if reason:
|
|
130
|
+
log.warning("rejected Skyvern callback: %s", reason)
|
|
131
|
+
return JSONResponse({"error": reason}, status_code=401), {}
|
|
132
|
+
try:
|
|
133
|
+
payload = json.loads(body) if body else {}
|
|
134
|
+
except ValueError:
|
|
135
|
+
payload = {}
|
|
136
|
+
identity_id = request.path_params["identity_id"]
|
|
137
|
+
if cfg.allowed_identity_ids is not None and identity_id not in cfg.allowed_identity_ids:
|
|
138
|
+
return JSONResponse({"error": "identity not allowed"}, status_code=403), {}
|
|
139
|
+
return None, payload if isinstance(payload, dict) else {}
|
|
140
|
+
|
|
141
|
+
async def email_code(request: Request) -> JSONResponse:
|
|
142
|
+
denied, payload = await authenticate(request)
|
|
143
|
+
if denied:
|
|
144
|
+
return denied
|
|
145
|
+
identity_id = request.path_params["identity_id"]
|
|
146
|
+
kind = request.query_params.get("kind", "code")
|
|
147
|
+
if kind not in ("code", "link", "any"):
|
|
148
|
+
return JSONResponse({"error": "kind must be code, link or any"}, status_code=400)
|
|
149
|
+
run = payload.get("workflow_run_id") or payload.get("task_id")
|
|
150
|
+
try:
|
|
151
|
+
async with client() as hl:
|
|
152
|
+
if kind == "code":
|
|
153
|
+
m = await hl.wait_for_code(identity_id, channel="email", timeout=cfg.wait_seconds)
|
|
154
|
+
elif kind == "link":
|
|
155
|
+
m = await hl.wait_for_link(identity_id, channel="email", timeout=cfg.wait_seconds)
|
|
156
|
+
else:
|
|
157
|
+
m = await hl.wait_for_message(identity_id, channel="email", timeout=cfg.wait_seconds)
|
|
158
|
+
except HumanlessTimeoutError:
|
|
159
|
+
return _no_code_yet("no new message yet")
|
|
160
|
+
except HumanlessError as e:
|
|
161
|
+
log.warning("humanless error for run %s: %s", run, e.code)
|
|
162
|
+
# 200 keeps Skyvern polling (an expired/unknown inbox will just time out the task with a clear log).
|
|
163
|
+
return _no_code_yet(f"humanless: {e.code}")
|
|
164
|
+
value = m.get("code") if kind != "link" and m.get("code") else m.get("url")
|
|
165
|
+
if not value:
|
|
166
|
+
return _no_code_yet("message had no code or link")
|
|
167
|
+
log.info("served %s to Skyvern run %s", "code" if value == m.get("code") else "link", run)
|
|
168
|
+
return JSONResponse({"verification_code": value})
|
|
169
|
+
|
|
170
|
+
async def authenticator_code(request: Request) -> JSONResponse:
|
|
171
|
+
denied, payload = await authenticate(request)
|
|
172
|
+
if denied:
|
|
173
|
+
return denied
|
|
174
|
+
identity_id = request.path_params["identity_id"]
|
|
175
|
+
authenticator_id = request.path_params["authenticator_id"]
|
|
176
|
+
path = f"/v1/identities/{quote(identity_id, safe='')}/authenticators/{quote(authenticator_id, safe='')}/code"
|
|
177
|
+
try:
|
|
178
|
+
async with client() as hl:
|
|
179
|
+
# humanless==0.1.1's Python SDK has no authenticator helpers yet: same auth/error handling via _request
|
|
180
|
+
r = await hl._request("GET", path)
|
|
181
|
+
if r["seconds_remaining"] <= 3: # would expire while Skyvern types it: wait for the next period
|
|
182
|
+
await asyncio.sleep(r["seconds_remaining"] + 0.5)
|
|
183
|
+
r = await hl._request("GET", path)
|
|
184
|
+
except HumanlessError as e:
|
|
185
|
+
log.warning("humanless error for run %s: %s", payload.get("workflow_run_id") or payload.get("task_id"), e.code)
|
|
186
|
+
return _no_code_yet(f"humanless: {e.code}")
|
|
187
|
+
return JSONResponse({"verification_code": r["code"]})
|
|
188
|
+
|
|
189
|
+
async def healthz(_: Request) -> JSONResponse:
|
|
190
|
+
return JSONResponse({"ok": True})
|
|
191
|
+
|
|
192
|
+
return Starlette(
|
|
193
|
+
routes=[
|
|
194
|
+
Route("/skyvern/totp/email/{identity_id}", email_code, methods=["POST"]),
|
|
195
|
+
Route("/skyvern/totp/authenticator/{identity_id}/{authenticator_id}", authenticator_code, methods=["POST"]),
|
|
196
|
+
Route("/healthz", healthz, methods=["GET"]),
|
|
197
|
+
]
|
|
198
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""The bridge against Skyvern's exact totp_url request/response contract, with Humanless mocked.
|
|
2
|
+
|
|
3
|
+
`skyvern_post` reproduces what skyvern 1.0.58 sends (skyvern/services/otp_service.py `_get_otp_value_from_url` +
|
|
4
|
+
skyvern/forge/sdk/core/security.py `generate_skyvern_webhook_signature`), and `skyvern_reads` what it accepts.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import hashlib
|
|
8
|
+
import hmac
|
|
9
|
+
import json
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
import pytest
|
|
14
|
+
from starlette.testclient import TestClient
|
|
15
|
+
|
|
16
|
+
from humanless_skyvern_bridge import BridgeConfig, create_app
|
|
17
|
+
|
|
18
|
+
SKYVERN_KEY = "sk_test_skyvern"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def skyvern_post(client: TestClient, path: str, payload: dict, api_key: str = SKYVERN_KEY, ts: int | None = None):
|
|
22
|
+
body = json.dumps(payload, separators=(",", ":"), ensure_ascii=False)
|
|
23
|
+
sig = hmac.new(api_key.encode(), msg=body.encode(), digestmod=hashlib.sha256).hexdigest()
|
|
24
|
+
headers = {"x-skyvern-timestamp": str(ts or int(time.time())), "x-skyvern-signature": sig, "Content-Type": "application/json"}
|
|
25
|
+
return client.post(path, content=body, headers=headers)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def skyvern_reads(res: httpx.Response):
|
|
29
|
+
"""Skyvern's acceptance: 200 + JSON object; the code is body['verification_code'] when truthy, else poll again."""
|
|
30
|
+
if res.status_code != 200:
|
|
31
|
+
return None
|
|
32
|
+
body = res.json()
|
|
33
|
+
assert isinstance(body, dict)
|
|
34
|
+
return body.get("verification_code") or None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class FakeHumanless:
|
|
38
|
+
def __init__(self):
|
|
39
|
+
self.messages: list[dict] = []
|
|
40
|
+
self.totp = [{"code": "222222", "seconds_remaining": 2}, {"code": "333333", "seconds_remaining": 30}]
|
|
41
|
+
self.calls: list[str] = []
|
|
42
|
+
|
|
43
|
+
def __call__(self, req: httpx.Request) -> httpx.Response:
|
|
44
|
+
self.calls.append(f"{req.method} {req.url.path}")
|
|
45
|
+
assert req.headers["authorization"] == "Bearer hl_live_test"
|
|
46
|
+
if req.url.path == "/v1/identities/id1/wait":
|
|
47
|
+
if self.messages:
|
|
48
|
+
return httpx.Response(200, json=self.messages.pop(0))
|
|
49
|
+
return httpx.Response(408, json={"error": {"code": "timeout", "message": "no message"}})
|
|
50
|
+
if req.url.path == "/v1/identities/id1/authenticators/au1/code":
|
|
51
|
+
return httpx.Response(200, json={"authenticator_id": "au1", **self.totp.pop(0)})
|
|
52
|
+
return httpx.Response(404, json={"error": {"code": "not_found", "message": "nope"}})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def msg(code=None, url=None):
|
|
56
|
+
return {"type": "otp" if code else "magic_link", "code": code, "url": url, "channel": "email", "sender": "s",
|
|
57
|
+
"subject": None, "received_at": "2026-12-04T00:00:00.000Z", "raw_snippet": ""}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.fixture
|
|
61
|
+
def fake():
|
|
62
|
+
return FakeHumanless()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.fixture
|
|
66
|
+
def client(fake):
|
|
67
|
+
cfg = BridgeConfig(humanless_api_key="hl_live_test", skyvern_api_key=SKYVERN_KEY, humanless_base_url="https://api.test",
|
|
68
|
+
wait_seconds=0.3, transport=httpx.MockTransport(fake))
|
|
69
|
+
return TestClient(create_app(cfg))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_email_code_is_served_in_skyverns_shape(client, fake):
|
|
73
|
+
fake.messages.append(msg(code="123456"))
|
|
74
|
+
res = skyvern_post(client, "/skyvern/totp/email/id1", {"task_id": "tsk_1"})
|
|
75
|
+
assert res.json() == {"verification_code": "123456"}
|
|
76
|
+
assert skyvern_reads(res) == "123456"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_no_message_yet_keeps_skyvern_polling(client):
|
|
80
|
+
res = skyvern_post(client, "/skyvern/totp/email/id1", {"workflow_run_id": "wr_1", "workflow_permanent_id": "wpid_1"})
|
|
81
|
+
assert res.status_code == 200
|
|
82
|
+
assert skyvern_reads(res) is None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_magic_link_kind(client, fake):
|
|
86
|
+
fake.messages.append(msg(url="https://app.test/verify?t=abc"))
|
|
87
|
+
res = skyvern_post(client, "/skyvern/totp/email/id1?kind=link", {"task_id": "tsk_1"})
|
|
88
|
+
assert skyvern_reads(res) == "https://app.test/verify?t=abc"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_any_kind_prefers_code(client, fake):
|
|
92
|
+
fake.messages.append(msg(code="999999", url="https://app.test/x"))
|
|
93
|
+
assert skyvern_reads(skyvern_post(client, "/skyvern/totp/email/id1?kind=any", {"task_id": "t"})) == "999999"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_authenticator_code_waits_out_an_expiring_period(client, fake):
|
|
97
|
+
started = time.monotonic()
|
|
98
|
+
res = skyvern_post(client, "/skyvern/totp/authenticator/id1/au1", {"task_id": "tsk_1"})
|
|
99
|
+
assert skyvern_reads(res) == "333333" # the first code had 2 s left: the bridge waited for the next one
|
|
100
|
+
assert time.monotonic() - started >= 2
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_humanless_errors_do_not_break_skyverns_poll(client):
|
|
104
|
+
res = skyvern_post(client, "/skyvern/totp/authenticator/id1/missing", {"task_id": "t"})
|
|
105
|
+
assert res.status_code == 200 and skyvern_reads(res) is None
|
|
106
|
+
assert "not_found" in res.json()["detail"]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@pytest.mark.parametrize(
|
|
110
|
+
"mutate, reason",
|
|
111
|
+
[
|
|
112
|
+
(lambda c: skyvern_post(c, "/skyvern/totp/email/id1", {"task_id": "t"}, api_key="wrong"), "bad x-skyvern-signature"),
|
|
113
|
+
(lambda c: skyvern_post(c, "/skyvern/totp/email/id1", {"task_id": "t"}, ts=int(time.time()) - 3600), "stale"),
|
|
114
|
+
(lambda c: c.post("/skyvern/totp/email/id1", json={"task_id": "t"}), "missing"),
|
|
115
|
+
],
|
|
116
|
+
)
|
|
117
|
+
def test_rejects_requests_not_signed_by_skyvern(client, fake, mutate, reason):
|
|
118
|
+
res = mutate(client)
|
|
119
|
+
assert res.status_code == 401 and reason in res.json()["error"]
|
|
120
|
+
assert fake.calls == [] # Humanless never touched
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_identity_allowlist(fake):
|
|
124
|
+
cfg = BridgeConfig(humanless_api_key="hl_live_test", skyvern_api_key=SKYVERN_KEY, humanless_base_url="https://api.test",
|
|
125
|
+
wait_seconds=0.3, transport=httpx.MockTransport(fake), allowed_identity_ids={"other"})
|
|
126
|
+
res = skyvern_post(TestClient(create_app(cfg)), "/skyvern/totp/email/id1", {"task_id": "t"})
|
|
127
|
+
assert res.status_code == 403 and fake.calls == []
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_from_env_requires_signature_key(monkeypatch):
|
|
131
|
+
monkeypatch.setenv("HUMANLESS_API_KEY", "hl_live_test")
|
|
132
|
+
monkeypatch.delenv("SKYVERN_API_KEY", raising=False)
|
|
133
|
+
monkeypatch.delenv("BRIDGE_ALLOW_UNSIGNED", raising=False)
|
|
134
|
+
with pytest.raises(SystemExit):
|
|
135
|
+
BridgeConfig.from_env()
|
|
136
|
+
monkeypatch.setenv("BRIDGE_WAIT_SECONDS", "99")
|
|
137
|
+
monkeypatch.setenv("SKYVERN_API_KEY", "sk")
|
|
138
|
+
assert BridgeConfig.from_env().wait_seconds == 25.0 # capped under Skyvern's 30 s request timeout
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Live: the bridge against the real Humanless API, called exactly the way Skyvern calls a totp_url.
|
|
2
|
+
|
|
3
|
+
HUMANLESS_LIVE=1 and either:
|
|
4
|
+
* HUMANLESS_SANDBOX_KEY (or a freshly minted sandbox key): email path, with the Acme demo app sending the code;
|
|
5
|
+
* HUMANLESS_API_KEY: authenticator path (imports a throwaway TOTP secret, checks the code, deletes the identity).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import base64
|
|
9
|
+
import hashlib
|
|
10
|
+
import hmac
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
import secrets
|
|
14
|
+
import struct
|
|
15
|
+
import time
|
|
16
|
+
|
|
17
|
+
import httpx
|
|
18
|
+
import pytest
|
|
19
|
+
from starlette.testclient import TestClient
|
|
20
|
+
|
|
21
|
+
from humanless_skyvern_bridge import BridgeConfig, create_app
|
|
22
|
+
from tests.test_contract import SKYVERN_KEY, skyvern_post, skyvern_reads
|
|
23
|
+
|
|
24
|
+
API = os.environ.get("HUMANLESS_BASE_URL", "https://api.usehumanless.com")
|
|
25
|
+
pytestmark = [
|
|
26
|
+
pytest.mark.live,
|
|
27
|
+
pytest.mark.skipif(os.environ.get("HUMANLESS_LIVE") != "1", reason="set HUMANLESS_LIVE=1"),
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def totp(secret_b32: str, t: float, step: int = 30, digits: int = 6) -> str:
|
|
32
|
+
key = base64.b32decode(secret_b32)
|
|
33
|
+
mac = hmac.new(key, struct.pack(">Q", int(t // step)), hashlib.sha1).digest()
|
|
34
|
+
o = mac[-1] & 0x0F
|
|
35
|
+
return str((struct.unpack(">I", mac[o:o + 4])[0] & 0x7FFFFFFF) % 10**digits).zfill(digits)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def bridge(api_key: str) -> TestClient:
|
|
39
|
+
return TestClient(create_app(BridgeConfig(humanless_api_key=api_key, skyvern_api_key=SKYVERN_KEY, wait_seconds=20)))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.mark.skipif(not os.environ.get("HUMANLESS_API_KEY"), reason="needs HUMANLESS_API_KEY")
|
|
43
|
+
def test_authenticator_route_serves_the_right_totp():
|
|
44
|
+
key = os.environ["HUMANLESS_API_KEY"]
|
|
45
|
+
h = {"authorization": f"Bearer {key}"}
|
|
46
|
+
secret = base64.b32encode(secrets.token_bytes(20)).decode().rstrip("=")
|
|
47
|
+
with httpx.Client(base_url=API, headers=h, timeout=30) as hl:
|
|
48
|
+
idn = hl.post("/v1/identities", json={"channels": ["email"], "ttl_seconds": 600}).raise_for_status().json()
|
|
49
|
+
try:
|
|
50
|
+
au = hl.post(f"/v1/identities/{idn['identity_id']}/authenticators",
|
|
51
|
+
json={"secret": secret, "issuer": "bridge-live-test"}).raise_for_status().json()
|
|
52
|
+
res = skyvern_post(bridge(key), f"/skyvern/totp/authenticator/{idn['identity_id']}/{au['authenticator_id']}",
|
|
53
|
+
{"task_id": "tsk_live"})
|
|
54
|
+
now = time.time()
|
|
55
|
+
assert skyvern_reads(res) in {totp(secret, now), totp(secret, now - 30)}
|
|
56
|
+
finally:
|
|
57
|
+
hl.delete(f"/v1/identities/{idn['identity_id']}")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_email_route_serves_the_code_the_demo_app_sent():
|
|
61
|
+
key = os.environ.get("HUMANLESS_SANDBOX_KEY") or httpx.post(f"{API}/v1/sandbox/keys").raise_for_status().json()["key"]
|
|
62
|
+
h = {"authorization": f"Bearer {key}"}
|
|
63
|
+
with httpx.Client(base_url=API, headers=h, timeout=30) as hl:
|
|
64
|
+
idn = hl.post("/v1/identities", json={"channels": ["email"]}).raise_for_status().json()
|
|
65
|
+
try:
|
|
66
|
+
client = bridge(key)
|
|
67
|
+
# nothing sent yet: Skyvern is told to poll again
|
|
68
|
+
# (wait_seconds 20 would make this slow, so use a short-wait bridge for this one call)
|
|
69
|
+
quick = TestClient(create_app(BridgeConfig(humanless_api_key=key, skyvern_api_key=SKYVERN_KEY, wait_seconds=1)))
|
|
70
|
+
assert skyvern_reads(skyvern_post(quick, f"/skyvern/totp/email/{idn['identity_id']}", {"task_id": "t"})) is None
|
|
71
|
+
# the "site" (Acme demo) sends the code, as it would while Skyvern fills the sign-up form
|
|
72
|
+
page = httpx.post(f"{API}/demo/acme/signup", data={"email": idn["email"]}, timeout=30)
|
|
73
|
+
assert "Check your inbox" in page.text
|
|
74
|
+
code = skyvern_reads(skyvern_post(client, f"/skyvern/totp/email/{idn['identity_id']}", {"task_id": "tsk_live"}))
|
|
75
|
+
assert code and re.fullmatch(r"\d{6}", code)
|
|
76
|
+
verified = httpx.post(f"{API}/demo/acme/verify", data={"email": idn["email"], "code": code}, timeout=30)
|
|
77
|
+
assert "Email verified" in verified.text
|
|
78
|
+
finally:
|
|
79
|
+
hl.delete(f"/v1/identities/{idn['identity_id']}")
|