← 返回 Skills 市场
igorivanter

Headless OAuth

作者 Igor Ivanter · GitHub ↗ · v1.3.1 · MIT-0
cross-platform ✓ 安全检测通过
130
总下载
1
收藏
0
当前安装
5
版本数
在 OpenClaw 中安装
/install headless-oauth
功能描述
Authorize any OAuth CLI on a headless server where the agent and the user are on separate machines. Use when a CLI tool requires OAuth login on a VPS or serv...
使用说明 (SKILL.md)

Headless OAuth

Authorize CLI tools that require OAuth on a headless server — no browser needed on the server side.

⚠️ Agent Context: You Are on a Remote Server

You (the agent) are running on a remote VPS. The user is on a separate local machine with a browser.

This means:

  • You cannot open a browser yourself
  • The server's localhost is NOT accessible from the user's browser
  • The user must open all auth URLs on their own machine
  • When a redirect goes to a local address like http://127.0.0.1:PORT/callback?code=..., it will fail to load in the user's browser — that is expected and normal
  • The user should copy the full URL from the address bar (even if the page shows an error) and send it to you
  • You then forward that URL to the waiting server process via curl

Always make this explicit when asking the user to authorize. Example:

"Open this URL in your browser, log in, and approve. The page will likely fail to load — that's fine. Copy the full URL from the address bar and send it to me."


The Pattern

Split the browser flow across two machines:

SERVER                          LOCAL MACHINE
------                          -------------
1. Generate auth URL    →       2. Open URL in browser
                                3. Log in + grant permissions
                                4. Copy redirect URL or code
5. Exchange for token   ←
6. Store token locally

Most OAuth CLIs support this via flags like:

  • --no-launch-browser — gh (GitHub CLI), gcloud
  • --remote --step 1/2 — gog (Google Workspace CLI)
  • --manual — some generic CLIs
  • Device flow (code + URL, no redirect) — gh, some others

Keyring on Headless Servers

Many CLIs store tokens in a system keyring that requires an interactive terminal session to unlock. Check the CLI's documentation for a flag or environment variable that sets the keyring password non-interactively. Set it only for the duration of the auth step — do not persist it in shell configs or agent-global environment. Prefer injecting it from a secrets manager or an ephemeral shell session.


Google Workspace — gog CLI

gog supports headless auth via --remote --step 1/2. See the official gog docs for setup details.

Important: Use Desktop app OAuth client type in Google Cloud Console — not Web application. gog uses a random port for the callback, which Web clients reject with redirect_uri_mismatch.


GitHub CLI — gh

gh auth login --hostname github.com --git-protocol https --no-launch-browser
# → prints a one-time code and a URL
# Open https://github.com/login/device locally, enter the code
# gh polls and completes automatically once you approve

gcloud (Google Cloud CLI)

gcloud auth login --no-launch-browser
# → prints a URL
# Open in local browser, log in, copy the verification code shown, paste back

Generic Device Flow

If a CLI supports device flow (prints a short code + URL):

  1. Note the code and URL printed by the CLI
  2. Open the URL on any device
  3. Enter the code
  4. CLI polls and completes automatically — no redirect URL to copy

Manual Callback Relay (mcporter, custom OAuth servers)

Some tools (e.g. mcporter) start a local HTTP server on the server to catch the OAuth callback, but the user's browser can't reach that address on the remote server.

How to handle it:

  1. Start the auth command with a longer timeout so it doesn't expire while waiting for the user. Check the tool's docs for a timeout flag or environment variable.
  2. The tool usually prints a message like:
    If the browser did not open, visit https://... manually.
    
    Send that URL to the user.
  3. Tell the user:

    "Open this URL, log in and approve. The page will fail to load — that's normal. Copy the full URL from the address bar and send it to me."

  4. The user sends back something like: http://127.0.0.1:PORT/callback?code=...&state=...
  5. Forward it to the waiting server with curl:
    curl -s "http://127.0.0.1:PORT/callback?code=...&state=..."
    
  6. The tool receives the code, exchanges it for a token, and completes authorization.

Troubleshooting

Error Fix
redirect_uri_mismatch Use Desktop app OAuth client, not Web application
No TTY / keyring unlock fails Check the CLI's docs for a non-interactive keyring option
Access blocked (testing mode) Add your email as test user in Google consent screen settings
Commands fail silently Check if the CLI requires an account env var to be set
Token expired Re-run auth steps; most CLIs handle refresh automatically

Applying This Pattern to Any CLI

  1. Check --help for flags like --no-launch-browser, --remote, --manual, or --headless
  2. Check docs for "device flow" or "offline access"
  3. If the tool starts a local callback server but has no headless flag — use the Manual Callback Relay pattern above
  4. If none of the above work: use ssh -L port forwarding to tunnel the callback to your local machine
安全使用建议
This skill is a focused recipe for completing OAuth when the server is headless and the user has the browser. It legitimately asks the user to paste redirect URLs or device codes (these are sensitive authorization values). Before installing or using it: (1) Confirm you trust the agent/host — the agent will see short-lived auth codes and may store tokens on the server. (2) Prefer device flow where possible (no redirect URLs to copy). (3) Ensure the agent only forwards the copied URL to the server's localhost as described and not to any external endpoint. (4) Avoid persisting keyring passwords or tokens in shell startup files; use ephemeral secrets or a secrets manager for the auth step. The skill itself contains no hidden installs or unrelated credential requests and appears coherent with its stated purpose.
功能分析
Type: OpenClaw Skill Name: headless-oauth Version: 1.3.1 The skill provides legitimate instructions and patterns for performing OAuth authentication on headless servers for common CLI tools like GitHub (gh) and Google Cloud (gcloud). It includes a 'Manual Callback Relay' pattern using curl to localhost, which is a standard technique for handling redirects when a browser cannot reach the remote server's local network, and it contains no evidence of data exfiltration or malicious intent (SKILL.md, README.md).
能力标签
requires-oauth-token
能力评估
Purpose & Capability
The name/description match the SKILL.md content. All required actions (asking the user to open URLs, copying redirect URLs or device codes, relaying callbacks to localhost, and advising about keyrings) are directly relevant to headless OAuth and no unrelated credentials, binaries, or services are requested.
Instruction Scope
The instructions explicitly require the user to paste full redirect URLs or codes (which contain sensitive authorization codes) and tell the agent to forward those to the server via curl to localhost. This is expected for the workflow, but it means the agent will handle sensitive tokens/codes during the flow — users should be aware these values are secret and transient. The skill does not instruct the agent to read unrelated files or exfiltrate data to external hosts.
Install Mechanism
Instruction-only skill with no install spec and no code files. Nothing is written to disk or fetched at install time, which minimizes installation risk.
Credentials
The skill requests no environment variables or credentials, which is proportional. It does advise storing tokens locally (as any OAuth flow does) and warns about keyring unlocking. Users should avoid persisting secrets in shell configs and prefer ephemeral injection from a secrets manager.
Persistence & Privilege
The skill does not request permanent presence (always:false) and does not modify other skills or system-wide settings. Autonomous invocation is allowed by platform default but not by this skill's configuration alone.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install headless-oauth
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /headless-oauth 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.3.1
Fix README: remove stale env var examples and bashrc persistence suggestion.
v1.3.0
Remove all specific env var names and binary install instructions. Add Manual Callback Relay pattern for mcporter/MCP servers. Add explicit agent context guidance (remote server / local browser split). Update description to reflect all three OAuth patterns.
v1.0.2
Remove recommendation to persist keyring passwords in shell/agent config. Add explicit security guidance throughout.
v1.0.1
Remove personal data from examples, improve security guidance around keyring passwords, fix README badge.
v1.0.0
Initial release: authorize any OAuth CLI on a headless server.
元数据
Slug headless-oauth
版本 1.3.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 5
常见问题

Headless OAuth 是什么?

Authorize any OAuth CLI on a headless server where the agent and the user are on separate machines. Use when a CLI tool requires OAuth login on a VPS or serv... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 130 次。

如何安装 Headless OAuth?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install headless-oauth」即可一键安装,无需额外配置。

Headless OAuth 是免费的吗?

是的,Headless OAuth 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Headless OAuth 支持哪些平台?

Headless OAuth 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Headless OAuth?

由 Igor Ivanter(@igorivanter)开发并维护,当前版本 v1.3.1。

💬 留言讨论