2727)
2828from ...types .auth import oauth_create_token_params , oauth_revoke_token_params , oauth_introspect_token_params
2929from ..._base_client import make_request_options
30+ from ...types .auth .token_response_if import TokenResponseIf
3031from ...types .auth .token_info_response_base_if import TokenInfoResponseBaseIf
3132
3233__all__ = ["OAuthResource" , "AsyncOAuthResource" ]
@@ -59,7 +60,7 @@ def create_token(
5960 client_secret : str | Omit = omit ,
6061 code : str | Omit = omit ,
6162 code_verifier : str | Omit = omit ,
62- grant_type : Literal ["authorization_code" , "refresh_token" ] | Omit = omit ,
63+ grant_type : Literal ["authorization_code" , "client_credentials" , " refresh_token" ] | Omit = omit ,
6364 redirect_uri : str | Omit = omit ,
6465 refresh_token : str | Omit = omit ,
6566 scope : str | Omit = omit ,
@@ -69,7 +70,7 @@ def create_token(
6970 extra_query : Query | None = None ,
7071 extra_body : Body | None = None ,
7172 timeout : float | httpx .Timeout | None | NotGiven = not_given ,
72- ) -> BinaryAPIResponse :
73+ ) -> TokenResponseIf :
7374 """
7475 Authenticates a client and returns access and refresh tokens.
7576
@@ -82,26 +83,28 @@ def create_token(
8283
8384 timeout: Override the client-level default timeout for this request, in seconds
8485 """
85- extra_headers = {"Accept" : "*/*" , ** (extra_headers or {})}
86- return self ._post (
87- "/oauth/2026-03/token" ,
88- body = maybe_transform (
89- {
90- "client_id" : client_id ,
91- "client_secret" : client_secret ,
92- "code" : code ,
93- "code_verifier" : code_verifier ,
94- "grant_type" : grant_type ,
95- "redirect_uri" : redirect_uri ,
96- "refresh_token" : refresh_token ,
97- "scope" : scope ,
98- },
99- oauth_create_token_params .OAuthCreateTokenParams ,
100- ),
101- options = make_request_options (
102- extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
86+ return cast (
87+ TokenResponseIf ,
88+ self ._post (
89+ "/oauth/2026-03/token" ,
90+ body = maybe_transform (
91+ {
92+ "client_id" : client_id ,
93+ "client_secret" : client_secret ,
94+ "code" : code ,
95+ "code_verifier" : code_verifier ,
96+ "grant_type" : grant_type ,
97+ "redirect_uri" : redirect_uri ,
98+ "refresh_token" : refresh_token ,
99+ "scope" : scope ,
100+ },
101+ oauth_create_token_params .OAuthCreateTokenParams ,
102+ ),
103+ options = make_request_options (
104+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
105+ ),
106+ cast_to = cast (Any , TokenResponseIf ), # Union types cannot be passed in as arguments in the type system
103107 ),
104- cast_to = BinaryAPIResponse ,
105108 )
106109
107110 def introspect_token (
@@ -224,7 +227,7 @@ async def create_token(
224227 client_secret : str | Omit = omit ,
225228 code : str | Omit = omit ,
226229 code_verifier : str | Omit = omit ,
227- grant_type : Literal ["authorization_code" , "refresh_token" ] | Omit = omit ,
230+ grant_type : Literal ["authorization_code" , "client_credentials" , " refresh_token" ] | Omit = omit ,
228231 redirect_uri : str | Omit = omit ,
229232 refresh_token : str | Omit = omit ,
230233 scope : str | Omit = omit ,
@@ -234,7 +237,7 @@ async def create_token(
234237 extra_query : Query | None = None ,
235238 extra_body : Body | None = None ,
236239 timeout : float | httpx .Timeout | None | NotGiven = not_given ,
237- ) -> AsyncBinaryAPIResponse :
240+ ) -> TokenResponseIf :
238241 """
239242 Authenticates a client and returns access and refresh tokens.
240243
@@ -247,26 +250,28 @@ async def create_token(
247250
248251 timeout: Override the client-level default timeout for this request, in seconds
249252 """
250- extra_headers = {"Accept" : "*/*" , ** (extra_headers or {})}
251- return await self ._post (
252- "/oauth/2026-03/token" ,
253- body = await async_maybe_transform (
254- {
255- "client_id" : client_id ,
256- "client_secret" : client_secret ,
257- "code" : code ,
258- "code_verifier" : code_verifier ,
259- "grant_type" : grant_type ,
260- "redirect_uri" : redirect_uri ,
261- "refresh_token" : refresh_token ,
262- "scope" : scope ,
263- },
264- oauth_create_token_params .OAuthCreateTokenParams ,
265- ),
266- options = make_request_options (
267- extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
253+ return cast (
254+ TokenResponseIf ,
255+ await self ._post (
256+ "/oauth/2026-03/token" ,
257+ body = await async_maybe_transform (
258+ {
259+ "client_id" : client_id ,
260+ "client_secret" : client_secret ,
261+ "code" : code ,
262+ "code_verifier" : code_verifier ,
263+ "grant_type" : grant_type ,
264+ "redirect_uri" : redirect_uri ,
265+ "refresh_token" : refresh_token ,
266+ "scope" : scope ,
267+ },
268+ oauth_create_token_params .OAuthCreateTokenParams ,
269+ ),
270+ options = make_request_options (
271+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
272+ ),
273+ cast_to = cast (Any , TokenResponseIf ), # Union types cannot be passed in as arguments in the type system
268274 ),
269- cast_to = AsyncBinaryAPIResponse ,
270275 )
271276
272277 async def introspect_token (
@@ -366,9 +371,8 @@ class OAuthResourceWithRawResponse:
366371 def __init__ (self , oauth : OAuthResource ) -> None :
367372 self ._oauth = oauth
368373
369- self .create_token = to_custom_raw_response_wrapper (
374+ self .create_token = to_raw_response_wrapper (
370375 oauth .create_token ,
371- BinaryAPIResponse ,
372376 )
373377 self .introspect_token = to_raw_response_wrapper (
374378 oauth .introspect_token ,
@@ -383,9 +387,8 @@ class AsyncOAuthResourceWithRawResponse:
383387 def __init__ (self , oauth : AsyncOAuthResource ) -> None :
384388 self ._oauth = oauth
385389
386- self .create_token = async_to_custom_raw_response_wrapper (
390+ self .create_token = async_to_raw_response_wrapper (
387391 oauth .create_token ,
388- AsyncBinaryAPIResponse ,
389392 )
390393 self .introspect_token = async_to_raw_response_wrapper (
391394 oauth .introspect_token ,
@@ -400,9 +403,8 @@ class OAuthResourceWithStreamingResponse:
400403 def __init__ (self , oauth : OAuthResource ) -> None :
401404 self ._oauth = oauth
402405
403- self .create_token = to_custom_streamed_response_wrapper (
406+ self .create_token = to_streamed_response_wrapper (
404407 oauth .create_token ,
405- StreamedBinaryAPIResponse ,
406408 )
407409 self .introspect_token = to_streamed_response_wrapper (
408410 oauth .introspect_token ,
@@ -417,9 +419,8 @@ class AsyncOAuthResourceWithStreamingResponse:
417419 def __init__ (self , oauth : AsyncOAuthResource ) -> None :
418420 self ._oauth = oauth
419421
420- self .create_token = async_to_custom_streamed_response_wrapper (
422+ self .create_token = async_to_streamed_response_wrapper (
421423 oauth .create_token ,
422- AsyncStreamedBinaryAPIResponse ,
423424 )
424425 self .introspect_token = async_to_streamed_response_wrapper (
425426 oauth .introspect_token ,
0 commit comments