6363)
6464from ._utils import is_dict , is_list , asyncify , is_given , lru_cache , is_mapping
6565from ._compat import PYDANTIC_V1 , model_copy , model_dump
66- from ._models import GenericModel , FinalRequestOptions , validate_type , construct_type
66+ from ._models import GenericModel , SecurityOptions , FinalRequestOptions , validate_type , construct_type
6767from ._response import (
6868 APIResponse ,
6969 BaseAPIResponse ,
@@ -432,9 +432,27 @@ def _make_status_error(
432432 ) -> _exceptions .APIStatusError :
433433 raise NotImplementedError ()
434434
435+ def _auth_headers (
436+ self ,
437+ security : SecurityOptions , # noqa: ARG002
438+ ) -> dict [str , str ]:
439+ return {}
440+
441+ def _auth_query (
442+ self ,
443+ security : SecurityOptions , # noqa: ARG002
444+ ) -> dict [str , str ]:
445+ return {}
446+
447+ def _custom_auth (
448+ self ,
449+ security : SecurityOptions , # noqa: ARG002
450+ ) -> httpx .Auth | None :
451+ return None
452+
435453 def _build_headers (self , options : FinalRequestOptions , * , retries_taken : int = 0 ) -> httpx .Headers :
436454 custom_headers = options .headers or {}
437- headers_dict = _merge_mappings (self .default_headers , custom_headers )
455+ headers_dict = _merge_mappings ({ ** self ._auth_headers ( options . security ), ** self . default_headers } , custom_headers )
438456 self ._validate_headers (headers_dict , custom_headers )
439457
440458 # headers are case-insensitive while dictionaries are not.
@@ -506,7 +524,7 @@ def _build_request(
506524 raise RuntimeError (f"Unexpected JSON data type, { type (json_data )} , cannot merge with `extra_body`" )
507525
508526 headers = self ._build_headers (options , retries_taken = retries_taken )
509- params = _merge_mappings (self .default_query , options .params )
527+ params = _merge_mappings ({ ** self ._auth_query ( options . security ), ** self . default_query } , options .params )
510528 content_type = headers .get ("Content-Type" )
511529 files = options .files
512530
@@ -671,7 +689,6 @@ def default_headers(self) -> dict[str, str | Omit]:
671689 "Content-Type" : "application/json" ,
672690 "User-Agent" : self .user_agent ,
673691 ** self .platform_headers (),
674- ** self .auth_headers ,
675692 ** self ._custom_headers ,
676693 }
677694
@@ -990,8 +1007,9 @@ def request(
9901007 self ._prepare_request (request )
9911008
9921009 kwargs : HttpxSendArgs = {}
993- if self .custom_auth is not None :
994- kwargs ["auth" ] = self .custom_auth
1010+ custom_auth = self ._custom_auth (options .security )
1011+ if custom_auth is not None :
1012+ kwargs ["auth" ] = custom_auth
9951013
9961014 if options .follow_redirects is not None :
9971015 kwargs ["follow_redirects" ] = options .follow_redirects
@@ -1952,6 +1970,7 @@ def make_request_options(
19521970 idempotency_key : str | None = None ,
19531971 timeout : float | httpx .Timeout | None | NotGiven = not_given ,
19541972 post_parser : PostParser | NotGiven = not_given ,
1973+ security : SecurityOptions | None = None ,
19551974) -> RequestOptions :
19561975 """Create a dict of type RequestOptions without keys of NotGiven values."""
19571976 options : RequestOptions = {}
@@ -1977,6 +1996,9 @@ def make_request_options(
19771996 # internal
19781997 options ["post_parser" ] = post_parser # type: ignore
19791998
1999+ if security is not None :
2000+ options ["security" ] = security
2001+
19802002 return options
19812003
19822004
0 commit comments