Skip to content

Commit 9ab6603

Browse files
feat(api): Fixing api key auth (#22)
1 parent 94978b8 commit 9ab6603

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openint%2Fopenint-a33b999e54f4c80e7d83d29703b3936b2a821474af967faa2737c4fb281281c4.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openint%2Fopenint-d64965bcfd85daaf90f1831a59b4f8ce7f3e909e53f87f00c3d4b213b53b597f.yml

src/openint/_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _api_key(self) -> dict[str, str]:
143143
api_key = self.api_key
144144
if api_key is None:
145145
return {}
146-
return {"authorization": api_key}
146+
return {"Authorization": f"Bearer {api_key}"}
147147

148148
@property
149149
def _customer_token(self) -> dict[str, str]:
@@ -163,9 +163,9 @@ def default_headers(self) -> dict[str, str | Omit]:
163163

164164
@override
165165
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
166-
if self.api_key and headers.get("authorization"):
166+
if self.api_key and headers.get("Authorization"):
167167
return
168-
if isinstance(custom_headers.get("authorization"), Omit):
168+
if isinstance(custom_headers.get("Authorization"), Omit):
169169
return
170170

171171
if self.customer_token and headers.get("Authorization"):
@@ -174,7 +174,7 @@ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
174174
return
175175

176176
raise TypeError(
177-
'"Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `authorization` or `Authorization` headers to be explicitly omitted"'
177+
'"Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
178178
)
179179

180180
def copy(
@@ -829,7 +829,7 @@ def _api_key(self) -> dict[str, str]:
829829
api_key = self.api_key
830830
if api_key is None:
831831
return {}
832-
return {"authorization": api_key}
832+
return {"Authorization": f"Bearer {api_key}"}
833833

834834
@property
835835
def _customer_token(self) -> dict[str, str]:
@@ -849,9 +849,9 @@ def default_headers(self) -> dict[str, str | Omit]:
849849

850850
@override
851851
def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
852-
if self.api_key and headers.get("authorization"):
852+
if self.api_key and headers.get("Authorization"):
853853
return
854-
if isinstance(custom_headers.get("authorization"), Omit):
854+
if isinstance(custom_headers.get("Authorization"), Omit):
855855
return
856856

857857
if self.customer_token and headers.get("Authorization"):
@@ -860,7 +860,7 @@ def _validate_headers(self, headers: Headers, custom_headers: Headers) -> None:
860860
return
861861

862862
raise TypeError(
863-
'"Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `authorization` or `Authorization` headers to be explicitly omitted"'
863+
'"Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
864864
)
865865

866866
def copy(

tests/test_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,21 +326,21 @@ def test_default_headers_option(self) -> None:
326326
def test_validate_headers(self) -> None:
327327
client = Openint(base_url=base_url, api_key=api_key, _strict_response_validation=True)
328328
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
329-
assert request.headers.get("authorization") == api_key
329+
assert request.headers.get("Authorization") == f"Bearer {api_key}"
330330

331331
with update_env(**{"OPENINT_API_KEY": Omit()}):
332332
client2 = Openint(base_url=base_url, api_key=None, _strict_response_validation=True)
333333

334334
with pytest.raises(
335335
TypeError,
336-
match="Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `authorization` or `Authorization` headers to be explicitly omitted",
336+
match="Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted",
337337
):
338338
client2._build_request(FinalRequestOptions(method="get", url="/foo"))
339339

340340
request2 = client2._build_request(
341-
FinalRequestOptions(method="get", url="/foo", headers={"authorization": Omit()})
341+
FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()})
342342
)
343-
assert request2.headers.get("authorization") is None
343+
assert request2.headers.get("Authorization") is None
344344

345345
def test_default_query_option(self) -> None:
346346
client = Openint(
@@ -1067,21 +1067,21 @@ def test_default_headers_option(self) -> None:
10671067
def test_validate_headers(self) -> None:
10681068
client = AsyncOpenint(base_url=base_url, api_key=api_key, _strict_response_validation=True)
10691069
request = client._build_request(FinalRequestOptions(method="get", url="/foo"))
1070-
assert request.headers.get("authorization") == api_key
1070+
assert request.headers.get("Authorization") == f"Bearer {api_key}"
10711071

10721072
with update_env(**{"OPENINT_API_KEY": Omit()}):
10731073
client2 = AsyncOpenint(base_url=base_url, api_key=None, _strict_response_validation=True)
10741074

10751075
with pytest.raises(
10761076
TypeError,
1077-
match="Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `authorization` or `Authorization` headers to be explicitly omitted",
1077+
match="Could not resolve authentication method. Expected either api_key or customer_token to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted",
10781078
):
10791079
client2._build_request(FinalRequestOptions(method="get", url="/foo"))
10801080

10811081
request2 = client2._build_request(
1082-
FinalRequestOptions(method="get", url="/foo", headers={"authorization": Omit()})
1082+
FinalRequestOptions(method="get", url="/foo", headers={"Authorization": Omit()})
10831083
)
1084-
assert request2.headers.get("authorization") is None
1084+
assert request2.headers.get("Authorization") is None
10851085

10861086
def test_default_query_option(self) -> None:
10871087
client = AsyncOpenint(

0 commit comments

Comments
 (0)