@@ -154,7 +154,7 @@ def authorization_url(self, url, state=None, **kwargs):
154154
155155 def fetch_token (self , token_url , code = None , authorization_response = None ,
156156 body = '' , auth = None , username = None , password = None , method = 'POST' ,
157- timeout = None , headers = None , verify = True , proxies = None , ** kwargs ):
157+ timeout = None , headers = None , verify = True , proxies = None , post_params = None , ** kwargs ):
158158 """Generic method for fetching an access token from the token endpoint.
159159
160160 If you are using the MobileApplicationClient you will want to use
@@ -177,6 +177,7 @@ def fetch_token(self, token_url, code=None, authorization_response=None,
177177 :param timeout: Timeout of the request in seconds.
178178 :param verify: Verify SSL certificate.
179179 :param kwargs: Extra parameters to include in the token request.
180+ :param post_params: If True, sends body as url query string.
180181 :return: A token dict
181182 """
182183 if not is_secure_transport (token_url ):
@@ -215,11 +216,16 @@ def fetch_token(self, token_url, code=None, authorization_response=None,
215216 'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8' ,
216217 }
217218 self .token = {}
218- if method .upper () == 'POST' :
219+ if method .upper () == 'POST' and not post_params :
219220 r = self .post (token_url , data = dict (urldecode (body )),
220221 timeout = timeout , headers = headers , auth = auth ,
221222 verify = verify , proxies = proxies )
222223 log .debug ('Prepared fetch token request body %s' , body )
224+ elif method .upper () == 'POST' :
225+ r = self .post (token_url , params = dict (urldecode (body )),
226+ timeout = timeout , headers = headers , auth = auth ,
227+ verify = verify , proxies = proxies )
228+ log .debug ('Prepared fetch token request body %s' , body )
223229 elif method .upper () == 'GET' :
224230 # if method is not 'POST', switch body to querystring and GET
225231 r = self .get (token_url , params = dict (urldecode (body )),
@@ -258,7 +264,7 @@ def token_from_fragment(self, authorization_response):
258264 return self .token
259265
260266 def refresh_token (self , token_url , refresh_token = None , body = '' , auth = None ,
261- timeout = None , headers = None , verify = True , proxies = None , ** kwargs ):
267+ timeout = None , headers = None , verify = True , proxies = None , post_params = None , ** kwargs ):
262268 """Fetch a new access token using a refresh token.
263269
264270 :param token_url: The token endpoint, must be HTTPS.
@@ -269,6 +275,7 @@ def refresh_token(self, token_url, refresh_token=None, body='', auth=None,
269275 :param timeout: Timeout of the request in seconds.
270276 :param verify: Verify SSL certificate.
271277 :param kwargs: Extra parameters to include in the token request.
278+ :param post_params: If True, sends body as url query string.
272279 :return: A token dict
273280 """
274281 if not token_url :
@@ -293,8 +300,11 @@ def refresh_token(self, token_url, refresh_token=None, body='', auth=None,
293300 'application/x-www-form-urlencoded;charset=UTF-8'
294301 ),
295302 }
296-
297- r = self .post (token_url , data = dict (urldecode (body )), auth = auth ,
303+ if not post_params :
304+ r = self .post (token_url , data = dict (urldecode (body )), auth = auth ,
305+ timeout = timeout , headers = headers , verify = verify , withhold_token = True , proxies = proxies )
306+ else :
307+ r = self .post (token_url , data = params (urldecode (body )), auth = auth ,
298308 timeout = timeout , headers = headers , verify = verify , withhold_token = True , proxies = proxies )
299309 log .debug ('Request to refresh token completed with status %s.' ,
300310 r .status_code )
0 commit comments