Files
broker/reference_tools/minimal_auth_showcase.py
T
coreci 7f7868f7cf docs(milestone): complete coreci-broker
---ci---
phase: 5
milestone: v0.1
status: complete
requirements:
  covered: [REQ-01, REQ-02, REQ-03, REQ-04, REQ-05, REQ-06, REQ-07, REQ-08, REQ-09, REQ-10, REQ-11, REQ-12, REQ-13, REQ-14, REQ-15, REQ-16, REQ-17, REQ-18, REQ-19, REQ-20]
  partial: []
---/ci---
2026-10-10 15:30:14 +00:00

45 lines
1.5 KiB
Python

"""title: Minimal Auth Showcase [CoreCI]
author: coreci
description: Minimal Open WebUI tool template showing the CoreCI Broker pattern - authenticate with the broker first, then use a second tool.
version: 0.1.0
requirements: []
licence: MIT
"""
import coreci_broker_client
class Tools:
class Valves:
base_url = ""
agent_id = ""
app_uuid = ""
user_id = ""
def __init__(self):
self.valves = self.Valves()
self._state = {}
def _client(self):
return coreci_broker_client.BrokerClient(
self.valves.base_url, self.valves.agent_id,
self.valves.app_uuid, self.valves.user_id, ["coreci"],
)
def demo(self, context=None) -> dict:
"""Demonstrate broker auth before any downstream tool call.
Ensures the agent is registered with the broker (idempotent), then
reads the agent's own secret through the client: the credential
fetch itself proves the auth path works before any second tool
would use the credential. The secret material never appears in the
returned marker.
:param context: optional Open WebUI call context, unused
:return: marker dict with registered and secret_read flags
"""
client = self._client()
client.ensure_registered(self._state)
client.read_secret("coreci/%s" % self.valves.agent_id, self._state)
return {"registered": True, "secret_read": True,
"path": "coreci/%s" % self.valves.agent_id,
"note": "auth first, then use"}