Skip to content

Commit ea4796f

Browse files
feat: add private config install script with browser auth flow
When curl hits a private config, returns a script that opens browser for OAuth, polls for token, then re-fetches with auth. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 14846d8 commit ea4796f

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/lib/server/install-script.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,84 @@ function sanitizeShellArg(value: string): string {
22
return value.replace(/[^a-zA-Z0-9_\-]/g, '');
33
}
44

5+
export function generatePrivateInstallScript(
6+
appUrl: string,
7+
username: string,
8+
slug: string
9+
): string {
10+
const safeUsername = sanitizeShellArg(username);
11+
const safeSlug = sanitizeShellArg(slug);
12+
13+
return `#!/bin/bash
14+
set -e
15+
16+
echo "========================================"
17+
echo " OpenBoot - Private Config Install"
18+
echo " Config: @${safeUsername}/${safeSlug}"
19+
echo "========================================"
20+
echo ""
21+
echo "This config is private. Browser authorization required."
22+
echo ""
23+
24+
APP_URL="${appUrl}"
25+
26+
auth_response=$(curl -fsSL -X POST "\$APP_URL/api/auth/cli/start" \\
27+
-H "Content-Type: application/json" \\
28+
-d '{}')
29+
30+
CODE_ID=$(echo "\$auth_response" | grep -o '"code_id":"[^"]*"' | cut -d'"' -f4)
31+
CODE=$(echo "\$auth_response" | grep -o '"code":"[^"]*"' | cut -d'"' -f4)
32+
33+
if [ -z "\$CODE_ID" ] || [ -z "\$CODE" ]; then
34+
echo "Error: Failed to start authentication"
35+
exit 1
36+
fi
37+
38+
AUTH_URL="\$APP_URL/cli-auth?code=\$CODE"
39+
echo "Opening browser for authorization..."
40+
echo " Code: \$CODE"
41+
echo " URL: \$AUTH_URL"
42+
echo ""
43+
44+
if command -v open &>/dev/null; then
45+
open "\$AUTH_URL"
46+
elif command -v xdg-open &>/dev/null; then
47+
xdg-open "\$AUTH_URL"
48+
else
49+
echo "Please open this URL in your browser:"
50+
echo " \$AUTH_URL"
51+
fi
52+
53+
echo "Waiting for authorization..."
54+
TOKEN=""
55+
for i in $(seq 1 60); do
56+
sleep 2
57+
poll_response=$(curl -fsSL "\$APP_URL/api/auth/cli/poll?code_id=\$CODE_ID" 2>/dev/null || echo '{}')
58+
poll_status=$(echo "\$poll_response" | grep -o '"status":"[^"]*"' | cut -d'"' -f4)
59+
60+
if [ "\$poll_status" = "approved" ]; then
61+
TOKEN=$(echo "\$poll_response" | grep -o '"token":"[^"]*"' | cut -d'"' -f4)
62+
break
63+
elif [ "\$poll_status" = "expired" ]; then
64+
echo "Error: Authorization expired. Please try again."
65+
exit 1
66+
fi
67+
printf "."
68+
done
69+
echo ""
70+
71+
if [ -z "\$TOKEN" ]; then
72+
echo "Error: Authorization timed out. Please try again."
73+
exit 1
74+
fi
75+
76+
echo "Authorized! Fetching install script..."
77+
echo ""
78+
79+
exec bash <(curl -fsSL -H "Authorization: Bearer \$TOKEN" "\$APP_URL/${safeUsername}/${safeSlug}/install")
80+
`;
81+
}
82+
583
export function generateInstallScript(
684
username: string,
785
slug: string,

0 commit comments

Comments
 (0)