@@ -154,7 +154,7 @@ def authorization_url(self, url, state=None, **kwargs):
154
154
155
155
def fetch_token (self , token_url , code = None , authorization_response = None ,
156
156
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 ):
158
158
"""Generic method for fetching an access token from the token endpoint.
159
159
160
160
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,
177
177
:param timeout: Timeout of the request in seconds.
178
178
:param verify: Verify SSL certificate.
179
179
:param kwargs: Extra parameters to include in the token request.
180
+ :param post_params: If True, sends body as url query string.
180
181
:return: A token dict
181
182
"""
182
183
if not is_secure_transport (token_url ):
@@ -215,11 +216,16 @@ def fetch_token(self, token_url, code=None, authorization_response=None,
215
216
'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8' ,
216
217
}
217
218
self .token = {}
218
- if method .upper () == 'POST' :
219
+ if method .upper () == 'POST' and not post_params :
219
220
r = self .post (token_url , data = dict (urldecode (body )),
220
221
timeout = timeout , headers = headers , auth = auth ,
221
222
verify = verify , proxies = proxies )
222
223
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 )
223
229
elif method .upper () == 'GET' :
224
230
# if method is not 'POST', switch body to querystring and GET
225
231
r = self .get (token_url , params = dict (urldecode (body )),
@@ -258,7 +264,7 @@ def token_from_fragment(self, authorization_response):
258
264
return self .token
259
265
260
266
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 ):
262
268
"""Fetch a new access token using a refresh token.
263
269
264
270
: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,
269
275
:param timeout: Timeout of the request in seconds.
270
276
:param verify: Verify SSL certificate.
271
277
:param kwargs: Extra parameters to include in the token request.
278
+ :param post_params: If True, sends body as url query string.
272
279
:return: A token dict
273
280
"""
274
281
if not token_url :
@@ -293,8 +300,11 @@ def refresh_token(self, token_url, refresh_token=None, body='', auth=None,
293
300
'application/x-www-form-urlencoded;charset=UTF-8'
294
301
),
295
302
}
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 ,
298
308
timeout = timeout , headers = headers , verify = verify , withhold_token = True , proxies = proxies )
299
309
log .debug ('Request to refresh token completed with status %s.' ,
300
310
r .status_code )
0 commit comments