33import base64
44import hashlib
55from typing import TYPE_CHECKING , Any , Literal , cast
6- from urllib .parse import urlencode
76
87from oauthlib .oauth1 import SIGNATURE_TYPE_AUTH_HEADER
98from requests_oauthlib import OAuth1
@@ -52,6 +51,7 @@ class OAuthAuth(BaseAuth):
5251 AUTHORIZATION_URL = ""
5352 ACCESS_TOKEN_URL = ""
5453 ACCESS_TOKEN_METHOD : Literal ["GET" , "POST" ] = "POST"
54+ ACCESS_TOKEN_PAYLOAD : Literal ["form" , "json" ] = "form"
5555 REVOKE_TOKEN_URL : str = ""
5656 REVOKE_TOKEN_METHOD : Literal ["GET" , "POST" , "DELETE" ] = "POST"
5757 ID_KEY = "id"
@@ -180,7 +180,7 @@ def revoke_token(self, token, uid):
180180 if revoke_token_url := self .revoke_token_url (token , uid ):
181181 params = self .revoke_token_params (token , uid )
182182 headers = self .revoke_token_headers (token , uid )
183- data = urlencode ( params ) if self .REVOKE_TOKEN_METHOD != "GET" else None
183+ data = params if self .REVOKE_TOKEN_METHOD != "GET" else None
184184 response = self .request (
185185 revoke_token_url ,
186186 params = params ,
@@ -420,7 +420,9 @@ def auth_complete_credentials(self):
420420
421421 def auth_headers (self ) -> Mapping [str , str | bytes ]:
422422 return {
423- "Content-Type" : "application/x-www-form-urlencoded" ,
423+ "Content-Type" : "application/json"
424+ if self .ACCESS_TOKEN_PAYLOAD == "json"
425+ else "application/x-www-form-urlencoded" ,
424426 "Accept" : "application/json" ,
425427 }
426428
@@ -445,13 +447,20 @@ def request_access_token(
445447 url : str ,
446448 method : Literal ["GET" , "POST" , "DELETE" ] = "GET" ,
447449 headers : Mapping [str , str | bytes ] | None = None ,
448- data : dict | bytes | str | None = None ,
450+ data : dict | None = None ,
451+ json : dict | None = None ,
449452 auth : tuple [str , str ] | AuthBase | None = None ,
450453 params : dict | None = None ,
451454 ) -> dict [Any , Any ]:
452455 with wrap_access_token_error (self ):
453456 return self .get_json (
454- url , method = method , headers = headers , data = data , auth = auth , params = params
457+ url ,
458+ method = method ,
459+ headers = headers ,
460+ data = data ,
461+ auth = auth ,
462+ params = params ,
463+ json = json ,
455464 )
456465
457466 def process_error (self , data ) -> None :
@@ -467,15 +476,19 @@ def auth_complete(self, *args, **kwargs):
467476 """Completes login process, must return user instance"""
468477 self .process_error (self .data )
469478 state = self .validate_state ()
470- data , params = None , None
479+ data = params = json = None
480+ auth_params = self .auth_complete_params (state )
471481 if self .ACCESS_TOKEN_METHOD == "GET" :
472- params = self .auth_complete_params (state )
482+ params = auth_params
483+ elif self .ACCESS_TOKEN_PAYLOAD == "json" :
484+ json = auth_params
473485 else :
474- data = self . auth_complete_params ( state )
486+ data = auth_params
475487
476488 response = self .request_access_token (
477489 self .access_token_url (),
478490 data = data ,
491+ json = json ,
479492 params = params ,
480493 headers = self .auth_headers (),
481494 auth = self .auth_complete_credentials (),
0 commit comments