fix: sso missing user id (#4082)

This commit is contained in:
Vlad Stan 2026-07-22 11:54:23 +03:00 committed by GitHub
parent 2223733c2d
commit eee372bb3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -326,7 +326,7 @@ async def api_delete_user_api_token(
async def login_with_sso_provider(
request: Request,
provider: str,
user_id: str | None,
user_id: str | None = None,
auth_user_id: str | None = Depends(optional_user_id),
):
provider_sso = _new_sso(provider)

View file

@ -58,6 +58,24 @@ async def test_auth_api_logout_and_update_ui_customization(
assert "cookie_access_token=" in logout.headers["set-cookie"]
@pytest.mark.anyio
async def test_auth_api_keycloak_login_without_user_id_redirects_to_provider(
http_client: AsyncClient, mocker
):
provider = "keycloak"
login_sso = _FakeSSO()
mocker.patch("lnbits.core.views.auth_api._new_sso", return_value=login_sso)
response = await http_client.get(f"/api/v1/auth/{provider}")
assert response.status_code == 307
assert response.headers["location"] == "https://example.com/sso/login"
assert login_sso.redirect_uri == (
f"{http_client.base_url}/api/v1/auth/{provider}/token"
)
assert login_sso.state is None
@pytest.mark.anyio
async def test_auth_api_sso_login_and_callback(http_client: AsyncClient, mocker):
user = await create_user_account(