Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions hermes_cli/dashboard_auth/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,16 @@ def _auto_sso_response(request: Request) -> Response | None:
# token-only credentials (drain/service providers) are never candidates.
providers = list_session_providers()
if len(providers) != 1:
# Zero → nothing to redirect to. Two+ → user must choose at /login.
# Zero -> nothing to redirect to. Two+ -> user must choose at /login.
return None

from hermes_cli.dashboard_auth.prefix import prefix_from_request

provider = providers[0]
# Password-only providers (supports_password=True) don't have an OAuth
# redirect flow - their start_login raises NotImplementedError. Skip
# auto-SSO and fall through to /login which renders the password form.
if getattr(provider, "supports_password", False):
return None
from hermes_cli.dashboard_auth.prefix import prefix_from_request
prefix = prefix_from_request(request)
next_param = _safe_next_target(request)
from urllib.parse import quote
Expand Down
9 changes: 9 additions & 0 deletions hermes_cli/dashboard_auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ async def auth_login(request: Request, provider: str, next: str = ""):
detail=f"Provider does not support interactive login: {provider!r}",
)

# Password-only providers don't have an OAuth redirect flow; redirect
# to /login which renders the username/password form.
if getattr(p, "supports_password", False):
from urllib.parse import quote
login_url = "/login"
if next:
login_url += f"?next={quote(next, safe='')}"
return RedirectResponse(url=login_url, status_code=302)

try:
ls = p.start_login(redirect_uri=_redirect_uri(request))
except ProviderError as e:
Expand Down