I Built a "Bridge" for APIs Muse Cannot Handle: Muse Auth Bridge
This is an English translation of the Japanese original, made with an LLM (Claude Opus 5.5). If anything is unclear, the Japanese version is authoritative. Read the Japanese original
For the Japanese original, the author planned the article and checked its content and references, and an LLM (Muse) was used to organize the structure and write the text. The author is responsible for the content.
1. Overview
The implementation introduced in this article is published on GitHub.
- Repository: https://github.com/reinforce-lab/muse-auth-bridge
- License: MIT
- Implementation: Cloudflare Workers (a shared core plus per-service adapters)
- Status: deployed to production (v0.2.5). All 9 smoke test items (including a breaker drill) passed in production, with 46 tests. Vendor secrets are not loaded yet, and connecting devices is still to come
When calling an external API from Muse, authentication that "just presents one value", like Bearer authentication, connects without trouble. On the other hand, authentication other than Bearer, such as authentication that needs a pair of an API key and a secret, or authentication that computes a signature for each request, does not connect as is.
The reason lies in how Muse handles credentials. The real values (the actual API keys and tokens) are stored in the Secure Vault and are not passed to the processing code. The code works with placeholder values, and just before a request goes out, the Secure Vault replaces the placeholders with the real values.
Authentication that works by substitution succeeds with this mechanism. Authentication that cannot be done by substitution does not. This article sorts out where that line is, and summarizes the design and implementation of "Muse Auth Bridge", an authentication translation layer I built to connect APIs on the other side of the line.
It started with Qingping, a CO2 sensor, and SwitchBot. Both have official APIs, but the former needs a pair of an App Key and an App Secret, and the latter needs a signature made from a token and a secret; both were on the other side of that line.
2. How credentials flow, and why some APIs do not connect

The flow is as shown in Figure 1.
A. A value that is only presented — works
Bearer tokens and a single API key in a header fall into this category. The code assembles a request containing a placeholder, which is replaced with the real value just before sending. From the API's point of view, it is a normal request presenting a legitimate value.
OAuth2 also fits this form, because the access token obtained through the authorization flow is ultimately presented as a Bearer token.
B. Two values — cannot be substituted
This is the case where the credential is a pair of two values, like an API key and a secret. The unit of registration and substitution is one value, so there is no format for handling a pair as is.
Qingping's API falls into this category. It is a client credentials flow: you obtain an access token with the pair of App Key and App Secret, then call the API with that token. Two values are needed at the very first step of obtaining the token.
C. Computing with a secret — there is no input for the computation
Signed requests fall into this category. With SwitchBot's API, you use a token and a secret to compute an HMAC-SHA256 signature over a string that includes a timestamp (t) and a nonce, and attach it to the headers of each request.
A signature is not "a value to present" but "the result of a computation that takes the secret as input". But the real secret stays outside the Secure Vault boundary, that is, it is never passed to the processing code. Even if you want to compute it, there is no input. And because the signature depends on the time and the request content, it cannot be inserted by substituting a prepared fixed value either.
In summary, the line is here:
- Can be substituted: authentication that presents one static value
- Cannot be substituted: authentication that needs a pair of values, and authentication that needs a computation with a secret as input
This is less a lack of implementation than a consequence of the design that keeps credentials away from code. In exchange for safety, the range of supported authentication methods is fixed.
3. Possible implementations
I considered mainly three ways to connect APIs on the other side of this line.
Option 1. Envelope — put the credentials in the token itself
This method encrypts the full set of vendor credentials with the public key of the bridge (the relay layer described later) and puts the ciphertext inside the Bearer token itself (like a JWE envelope).
With this method, the only secret the relay layer holds is its own private key. Because there is no need to put per-vendor secrets in the relay layer, it becomes a generic component that can be handed to anyone.
On the other hand, the full set of credentials still works as an identity card. If the token leaks, it can be used as is. It is an attractive option, but I passed on it this time and kept it as a candidate for v1.1.
Option 2. OAuth facade — wrap the whole thing in OAuth
This method makes the relay layer itself an OAuth2 authorization server and registers it on the Muse side as a normal OAuth connector. Lifecycle management such as issuing, revoking and refreshing tokens can be run with standard mechanisms.
However, revocation only works "when you notice a leak". On the other hand, OAuth has an advantage apart from revocation: short-lived access tokens expire automatically even if you never notice a leak, so they limit the window for replay. I acknowledge this advantage, and still did not adopt it. The reason is the burden of keeping an authorization server and the refresh lifecycle running as a personal operation. Whether Muse's connectors can handle refresh is unconfirmed, and I have kept it as a point to re-evaluate if it can be confirmed.
What I adopted instead is the breaker in the next section. Rather than lifecycle management, I prioritized "being able to stop everything in one place when I notice something wrong".
Option 3. Put an authentication translation layer outside — adopted
This method puts a thin relay layer on Cloudflare Workers and moves the translation of authentication methods into that layer. From the Muse side, this layer is "an ordinary API you can call with a Bearer token". In other words, the Muse side stays in the form inside the line, and the processing outside the line, such as signing and token exchange, all happens inside the Worker.
The form itself, "putting a thin layer in between", was inspired by Code-Hex's article on MuseKnock (a mechanism that delivers external webhooks to Muse via Cloudflare Workers). The bridge in this article applies that form to translating authentication.
Key point: Of the options considered, only "putting the translation layer outside" left the form on the Muse side unchanged. I kept the envelope as a future candidate, and rejected the OAuth facade because of the burden of personal operation, while acknowledging the advantage of short-lived tokens.
4. The implementation I chose — Muse Auth Bridge

The structure is as shown in Figure 2, and the implementation is split into two layers.
Shared core
It handles vendor-independent processing.
- Bearer authentication: the presented token is hashed with SHA-256 and compared in constant time, so that no information leaks through its length or prefix
- Role-based tokens: split into three roles,
read/write/admin. Daily use only usesread; write routes needwrite, and breaker operations needadmin. The roles are nested (admin ⊇ write ⊇ read). I considered making admin orthogonal and dedicated to the breaker, but for the token kept at hand for emergencies, I prioritized the simplicity of being able to deal with anything with that one token, and kept them nested - Allowlisted routes: the routes exposed are decided by a fixed allowlist. It is not a generic proxy. Even if a token leaks, only the defined routes open
- Write allowlists: for writes, routes alone are not fine-grained enough (section 5). SwitchBot commands pass only when explicitly listed in an allowlist of "device ID, command and commandType" combinations (
SWITCHBOT_ALLOWED_COMMANDS), and scenes only when listed in an allowlist of "scene IDs" (SWITCHBOT_ALLOWED_SCENES); if unset, every operation returns 403 even with awritetoken. The commandType is part of the key to prevent a custom infrared remote button sent withcommandType: "customize"from passing as a normal command of the same name. An allowlist entry written with two elements allows only normal commands (command); customize passes only when given explicitly as the third element. Since entries are written separated by colons, device IDs or command names that themselves contain a colon cannot be registered (such entries are ignored, failing toward rejection) - Rate limiting: however, the current implementation counts per Worker isolate, so it is not a global limit. This is stated as a known limitation in the code and the README
- Mapping vendor errors: errors returned by the vendor are not passed through as is, because the status codes the bridge itself returns and those the vendor returns mean different things even with the same number. Vendor 4xx and 5xx responses are all mapped to 502, and the kind is distinguished by error code (401 / 403 is
vendor_auth_error, 429 isvendor_rate_limited, 5xx isvendor_server_error, and other 4xx isvendor_client_error). The original status and body are kept. For example, if the vendor's 429 were returned as is, it could not be told apart from the bridge's own rate limiting (429). The rule for isolating problems is simple: every error response other than 502 (vendor_*) is one the bridge decided on and returned itself (successful responses return the vendor's JSON as is). Most 4xx responses from the bridge respond to problems on the caller's side, such as a wrong token, an insufficient role or invalid parameters; unexpected failures of the bridge itself return a JSON 500internal_error, an unconfigured adapter returns 501, and an active breaker returns 503. A 502 means a problem on the vendor side, and a bare (non-JSON) 5xx means a problem outside the Worker (in the runtime). When communication with the vendor itself fails (a network failure, a DNS failure, or any case where no response comes back), it is returned as 502vendor_unreachable. Errors that SwitchBot returns in the body'sstatusCodewhile keeping HTTP 200 (161 = device offline, and so on) are also caught as 502vendor_error - Breaker: a flag for stopping everything at once is placed at the checkpoint every request passes through
Per-service adapters
They handle only each vendor's authentication procedure. The shared core does not know vendor details, and the adapters do not know the bridge tokens.
- SwitchBot: computes
sign = Base64(HMAC-SHA256(secret, token + t + nonce))and attaches it to the headers together with the token. The secret is used only as the HMAC key and never leaves the Worker - Qingping: obtains an access token with client credentials using the App Key and App Secret, caches it and refreshes it before it expires. If a 401 comes back, it fetches a new token once and retries. In v1 it is read-only. To help isolate errors, failures are classified by where they happened and what kind they are. In both the token stage and the data stage, a failure of the communication itself is
vendor_unreachable, a vendor-side server failure (5xx) isvendor_server_error, and 502vendor_token_refusedis used only when the keys are rejected (401 / 403) (429 isvendor_rate_limitedand other 4xx isvendor_client_error, matching the mapping on the data side). This avoids mistaking network or vendor failures for "a key problem". Token caching is an optimization, so a failure to read or write KV does not stop the request. A read failure is treated as no cache and the token is fetched again; a write failure is logged and processing continues
Vendor secrets are stored encrypted as Worker secrets. The only secret the Muse side holds is a single Bearer token for the bridge. There is one exception. Qingping's access token (valid for about two hours) is cached in KV in plain text, to avoid issuing a new one on every request. This is documented in the operations runbook as a known trade-off whose impact is limited to a short-lived token.
Examples of the exposed routes:
| Method | Path | Role |
|---|---|---|
| GET | / |
Public (service description and route list) |
| GET | /health |
Public (503 while the breaker is active) |
| GET | /switchbot/devices |
read |
| POST | /switchbot/devices/:id/commands |
write |
| GET | /qingping/devices |
read |
| POST | /admin/breaker/on / /off |
admin |
The repository and license are as listed at the top. Invalid % escapes in a path return 400 (in my measurements, Cloudflare's edge also returns 400, so in practice it is guarded twice).
Key point: the bridge's responsibility is to confine signing and token exchange within the Worker. By separating the shared core from the adapters, adding a vendor only means adding an adapter.
5. Trade-offs on the side of safety
There are two points this design deliberately accepts.
Replay cannot be stopped
More precisely, not as long as a method that presents a static value is used. If that value is stolen, it can be resent (replayed) as is. Short-lived tokens would limit the window (Option 2), but with a static token it cannot be prevented. Adding a salt or nonce to requests does not help either, because they are resent along with it. A challenge-response that prevents resending requires "computing with a secret", which is exactly what Muse's credential model cannot do.
So the countermeasures lean not toward preventing replay but toward "keeping the damage small if it leaks, and being able to stop it right away": role-based tokens, allowlists, rate limiting, and the breaker.
The granularity of containment needs care. Allowing by route alone is not enough. For example, if SwitchBot's device operation route allowed "any command to any device", then the moment a smart lock was registered, a single write token would become an unlock key. So, as described in section 4, writes are narrowed down to "device ID, command and commandType" combinations, and rejecting everything is the default when unset.
The breaker, and measuring how it takes effect
The breaker takes effect before authentication. Even with a valid token, requests return 503 while the breaker is active. The only exception is the release route (/admin/breaker/off, admin required). A breaker that cannot be released becomes a trap, so this exception is intentional.
Checking before authentication also needs measures against side effects. Because even unauthenticated requests read KV for the check, an exception from a KV read could spread to every request. So when a read fails, it falls back to the last known state, and a 3-second read cache inside the isolate keeps unauthenticated traffic from increasing KV reads. The cache works even when the breaker key has not been created yet. What this reduces is only KV reads; it does not stop unauthenticated requests from starting the Worker. Serious protection would mean putting Cloudflare rate limiting rules in front, but I have given that lower priority for a personal operation.
The fallback also has limits. Only isolates that hold the cache have a last known state. An isolate newly started during a KV outage falls to the OFF side even if the breaker is ON, and requests pass. This is a deliberate choice that prioritizes availability, but there is indeed a path where "it opens even though you meant to stop it". When you need to stop it for certain, the operational line is to use BRIDGE_DISABLED, described next.
After deploying to production, I ran the smoke test (all 9 items), including actually switching on the breaker to confirm every route returned 503, and switching it off to confirm recovery, and every item passed.
That run revealed one thing. The KV storage where the breaker state is kept is eventually consistent, so a change can take up to about 60 seconds to propagate everywhere. When you need to "stop everything for certain right now", enabling the environment variable BRIDGE_DISABLED and redeploying is more reliable than the KV breaker. However, if BRIDGE_DISABLED is changed only in the Cloudflare dashboard, the next deploy overwrites it with the value in the configuration file. To stop it for certain, the configuration file (wrangler.toml) must also be changed. Also, when switching on the breaker, check durable: true in the response. If saving to KV fails, it becomes durable: false, and only the isolate that received the request is stopped; in that case too, switch to BRIDGE_DISABLED. These points are documented in the operating procedures (docs/OPERATIONS.md in the repository).
I also added an --expect-configured mode to the smoke test. After secrets are loaded, it treats a 501, which indicates an unconfigured adapter, as a failure rather than a pass.
As for the current state, vendor secrets have not been loaded yet. The target adapters return 501, indicating "not configured". The skeleton of the bridge and the authentication parts are running in production, and connecting devices is still to come.
Key point: accept what cannot be prevented (replay), and steer the design toward containing damage and stopping immediately. This is the core of the bridge on the side of safety.
6. Background — MCP and a specification for distributing skills
Finally, let me sort out the movements in specifications around this bridge.
MCP (Model Context Protocol) is a specification for connecting agents to tools. Until now, the "how to use" of a tool was prepared separately from the tool. Skills (procedure documents like SKILL.md) were placed on the agent side and used together with the tools.
This has two problems. When the tool is updated, the skill can remain outdated, and loading skills from the start that may or may not be used puts pressure on the context.
What has been proposed in response is "Skills over MCP". It is a specification that lets an MCP server distribute the skills themselves together with its tools, so the agent fetches the latest skill when it needs it (introduced as a beta as of November 2026).
An authentication bridge is a good match for this specification. Even if the mechanism of the bridge is simple, using it still involves judgment: which role's token to register in the connector, when and how to use the breaker, how to isolate the cause from symptoms. Procedures like these go stale less easily if they can be distributed together with the tool.
So in this repository, I put the form in which the bridge distributes its own usage skill in the design notes as a v1.1 candidate, like the envelope (Option 1). It is not in v1. The reasons are that Skills over MCP itself is a beta, and that the path by which Muse would take it in is unconfirmed. For now, the procedures remain in the repository as an operations runbook. That will be the material for turning them into skills.
Key point: a specification that distributes skills together with tools is a good match for "tools that come with procedures", like the bridge. But because it is a beta, adopting it remains a candidate for v1.1 or later.
7. Summary
- Muse's credentials follow a model where real values are not passed to code, and placeholders are replaced with real values just before sending
- So values that are only presented (Bearer, a single API key, OAuth2 access tokens) pass, but authentication that needs a pair of values and signatures computed with a secret do not
- As a solution, I put an authentication translation layer on Cloudflare Workers; the Muse side keeps a single Bearer token, and signing and token exchange happen inside the Worker
- What cannot be prevented, such as replay, is accepted, and the design leans toward containing damage (role-based tokens, allowlists of routes and operations) and stopping immediately (the breaker)
- Containment goes down not only to routes but to the granularity of operations (device, command and commandType combinations). Vendor errors (4xx and 5xx) are mapped to 502 so they do not mix with the bridge's own errors, an unreachable vendor is
vendor_unreachable, and unexpected failures of the bridge itself are a JSON 500internal_error, so the cause can be isolated from the symptom - Movements like Skills over MCP, which distributes how to use a tool as skills, are a candidate for v1.1 or later as a path to distribute the operating procedures of this kind of bridge
Next, I plan to buy an actual CO2 sensor, load the keys, and go as far as reading data through this bridge.