Skip to content

Commit 3e744c0

Browse files
committed
refactor: unify auth server client type params
1 parent e9c2709 commit 3e744c0

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

insforge/auth/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
from .models import UserResponse
2626

2727

28+
SERVER_CLIENT_TYPE_PARAMS = {"client_type": "server"}
29+
30+
2831
class AuthClient:
2932
def __init__(self, client: BaseClient) -> None:
3033
self._client = client
@@ -37,7 +40,8 @@ async def sign_in_with_password(
3740
) -> SignInResponse:
3841
payload = await self._client._request_json(
3942
"POST",
40-
"/api/auth/sessions?client_type=server",
43+
"/api/auth/sessions",
44+
params=SERVER_CLIENT_TYPE_PARAMS,
4145
json={"email": email, "password": password},
4246
exception_cls=InsforgeAuthError,
4347
)
@@ -126,7 +130,7 @@ async def create_user(
126130
response = await self._client._request_json(
127131
"POST",
128132
"/api/auth/users",
129-
params={"client_type": "server"},
133+
params=SERVER_CLIENT_TYPE_PARAMS,
130134
json=payload,
131135
exception_cls=InsforgeAuthError,
132136
)
@@ -168,7 +172,7 @@ async def refresh(
168172
payload = await self._client._request_json(
169173
"POST",
170174
"/api/auth/refresh",
171-
params={"client_type": "server"},
175+
params=SERVER_CLIENT_TYPE_PARAMS,
172176
json=RefreshRequest(refresh_token=refresh_token).model_dump(by_alias=True),
173177
exception_cls=InsforgeAuthError,
174178
)

tests/auth/test_auth_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ async def fake_request(method: str, url: httpx.URL, **kwargs: object) -> httpx.R
4343
assert result.access_token == "access"
4444
assert result.refresh_token == "refresh"
4545
assert captured["method"] == "POST"
46-
assert captured["url"] == "https://example.com/api/auth/sessions?client_type=server"
46+
assert captured["url"] == "https://example.com/api/auth/sessions"
47+
assert captured["kwargs"]["params"] == {"client_type": "server"}
4748
assert captured["kwargs"]["json"] == {"email": "a@example.com", "password": "secret"}
4849
assert captured["kwargs"]["headers"]["X-API-Key"] == "ins_test"
4950

0 commit comments

Comments
 (0)