/nlweb-protocol:nlweb-auth-multitenancyfrom nlweb-protocol
Configures NLWeb authentication with OAuth providers (GitHub, Google, Microsoft, Facebook), session storage, multi-tenant deployments, and per-user conversation persistence. Use when adding login, hosting multiple customers, or persisting chat history.
Ships in nlweb-protocol. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Fetch live docs:
AskAgent/python/webserver/routes/oauth.py for the current OAuth flow.AskAgent/python/core/conversation_history.py and storage_providers/ for persistence backends.config/config_oauth.yaml and config/config_storage.yaml for current keys.NLWeb ships OAuth-based user identification — it lets a logged-in user have persistent conversation memory tied to their identity. It does not ship:
If you need any of those, you build them as middleware on top.
Per config_oauth.yaml:
| Provider | Notes |
|---|---|
| GitHub | Standard OAuth 2.0 |
| Standard OAuth 2.0 | |
| Microsoft | Entra ID / personal accounts |
| Standard OAuth 2.0 |
Adding a new provider means a new client class in the OAuth routes module + a config entry. Verify the current extensibility mechanism in the live code.
| Route | Purpose |
|---|---|
GET /api/oauth/login/{provider} | Start the OAuth dance |
GET /api/oauth/callback/{provider} | OAuth callback handler |
GET /api/oauth/logout | End session |
GET /api/oauth/me | Current user info |
(Verify exact paths in webserver/routes/oauth.py.)
By default, NLWeb stores sessions in-memory or via an aiohttp session backend. For multi-instance deployments, configure a shared session store (Redis, etc.). The session cookie carries the user identity; conversation persistence keys off that identity.
config_storage.yaml selects which storage backend persists conversations:
| Backend | Notes |
|---|---|
Qdrant (qdrant_storage.py) | Conversations as vectors — enables conversation_search tool |
Azure AI Search (azure_search_storage.py) | Same idea, on Azure |
Elasticsearch (elasticsearch_storage.py) | Same idea, on ES |
The choice often matches your retrieval backend so conversation search and content search share infrastructure. Anonymous users typically don't get persistence — verify if/how the config exposes this toggle.
sites: Allowlistconfig_nlweb.yaml has a sites: list of allowed site names. Queries with site= not in the list are rejected. Patterns:
Single-tenant: just enumerate your own sites.
Multi-customer SaaS: prefix every site with a tenant ID (tenant_a__products, tenant_b__products), and add middleware that:
site params to scope to that tenant's sites onlyNLWeb does not ship this middleware — you write it.
At the retrieval layer:
qdrant_tenant_a, qdrant_tenant_b) and route based on the authenticated user.The strong-isolation path requires more config wrangling but is the only safe choice for regulated tenants.
methods/conversation_search.py queries the conversation storage scoped to the current user. The user ID flows from the OAuth session into the handler context. Without OAuth, this tool returns empty.
NLWeb's in-stream "headers" (the message_type JSON objects in SSE) include usage_terms and rate_limits. These can carry per-user policy — e.g., a higher-tier user gets a higher rate_limits.daily_quota. NLWeb doesn't enforce this; the client agent inspects and respects it.
https://your-host/api/oauth/callback/github.config_oauth.yaml):
GITHUB_OAUTH_CLIENT_ID=...
GITHUB_OAUTH_CLIENT_SECRET=...
config_oauth.yaml to enable the provider:
providers:
github:
enabled: true
scopes: ["read:user"]
/api/oauth/login/github to test.A sketch (aiohttp middleware):
@web.middleware
async def tenant_scope_middleware(request, handler):
user = await get_user_from_session(request)
if user is None:
return web.json_response({"error": "auth required"}, status=401)
requested_site = request.query.get("site") or ""
allowed_prefix = f"{user['tenant_id']}__"
if not requested_site.startswith(allowed_prefix):
return web.json_response({"error": "site not in tenant scope"}, status=403)
return await handler(request)
Register on the aiohttp app before NLWeb's own handlers. Verify the exact insertion point in webserver/aiohttp_server.py.
config_storage.yaml (Qdrant for dev, Azure Search / ES for prod).user_id on each conversation row — it does in current code; verify after upgrade.For public sites:
/ask but skip persistenceconversation_search tool for anonymous users (it would return empty anyway)Confirm the current behavior — anonymous policy has changed across releases.
NLWeb does NOT ship API key auth out of the box. Add it as middleware:
@web.middleware
async def api_key_middleware(request, handler):
key = request.headers.get("X-API-Key")
if request.path.startswith("/api/oauth/"):
return await handler(request) # OAuth flow exempt
if not is_valid_key(key):
return web.json_response({"error": "invalid key"}, status=401)
return await handler(request)
Issue keys via a separate admin endpoint or out-of-band.
aiohttp-session redis storage).Secure, HttpOnly, SameSite=Lax).who endpoint exposes tenant names — disable who_endpoint_enabled for multitenant deployments.Always re-fetch the OAuth and storage docs from the live repo — auth code moves between releases.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin nlweb-protocol13 skills in this plugin
/nlweb-ask-endpointImplement and consume the NLWeb /ask REST endpoint — request shape (GET/POST, query-string and v0.55 structured body), SSE streaming response, modes (list/summarize/generate), in-stream "message_type" headers, error envelopes, and client-side parsing. Use when building an NLWeb server route, calling /ask from a custom agent, or debugging /ask responses./nlweb-chatgpt-appsdkIntegrate NLWeb with ChatGPT's Apps SDK — the Node.js MCP server in `openai-apps-sdk-integration/`, the `nlweb-list` tool, the React widget at `ui://widget/nlweb-list.html`, and the port-8100 AppSDK adapter that translates NLWeb's message list to OpenAI Apps SDK envelopes. Use when publishing an NLWeb site as a ChatGPT app or wiring NLWeb results into an Apps SDK widget./nlweb-Other plugins' skills for the same job