HKUDS/nanobot · error · ValueError

signing key not found for kid=

Error message

signing key not found for kid={kid}

What it means

Validation failure in _validate_inbound_auth: the token header's kid does not match any key in the fetched Bot Framework JWKS, so the token was not signed by a recognized Bot Framework signing key (possibly stale JWKS cache or a forged token).

Solutions

  1. Wait for the cached JWKS to expire (1h TTL) or restart the gateway to force a refetch if Bot Framework rotated its signing keys
  2. Verify outbound HTTPS access to login.botframework.com OpenID/JWKS endpoints
  3. Reject the request with 401; an unknown kid on a fresh JWKS indicates a forged token
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nanobot/channels/msteams/runtime.py:493 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26). Data as JSON: /api/errors/12bb94efb0de2994. Report an issue: GitHub.

Appendix: source

Thrown at nanobot/channels/msteams/runtime.py:493

            raise RuntimeError("PyJWT not installed. Run: nanobot plugins enable msteams")

        if not auth_header.lower().startswith("bearer "):
            raise ValueError("missing bearer token")

        token = auth_header.split(" ", 1)[1].strip()
        if not token:
            raise ValueError("empty bearer token")

        header = jwt.get_unverified_header(token)
        kid = str(header.get("kid") or "").strip()
        if not kid:
            raise ValueError("missing token kid")

        jwks = await self._get_botframework_jwks()
        keys = cast(list[dict[str, Any]], jwks.get("keys") or [])
        jwk = next((key for key in keys if key.get("kid") == kid), None)
        if not jwk:
            raise ValueError(f"signing key not found for kid={kid}")

        public_key = RSAAlgorithm.from_jwk(json.dumps(jwk))
        claims = jwt.decode(
            token,
            key=cast(Any, public_key),
            algorithms=["RS256"],
            audience=self.config.app_id,
            issuer="https://api.botframework.com",
            options={
                "require": ["exp", "nbf", "iss", "aud"],
            },
        )

        claim_service_url = str(
            claims.get("serviceurl") or claims.get("serviceUrl") or "",
        ).strip()
        activity_service_url = str(activity.get("serviceUrl") or "").strip()
        if claim_service_url and activity_service_url and claim_service_url != activity_service_url:

View on GitHub (pinned to 42f37dc4c0)