@@ -44,20 +44,15 @@ class OAuth2FlowNoRedirectResult(object):
44
44
45
45
def __init__ (self , access_token , account_id , user_id , refresh_token , expiration , scope ):
46
46
"""
47
- Args:
48
- access_token (str): Token to be used to authenticate later
49
- requests.
50
- refresh_token (str): Token to be used to acquire new access token
51
- when existing one expires
52
- expiration (int, datetime): Either the number of seconds from now that the token expires
53
- in or the datetime at which the token expires
54
- account_id (str): The Dropbox user's account ID.
55
- user_id (str): Deprecated (use account_id instead).
56
- refresh_token (str): Token to be used to acquire new access token
57
- when existing one expires
58
- expiration (int, datetime): Either the number of seconds from now that the token expires
59
- in or the datetime at which the token expires
60
- scope (list): list of scopes to request in base oauth flow.
47
+ :param str access_token: Token to be used to authenticate later requests.
48
+ :param str account_id: The Dropbox user's account ID.
49
+ :param str user_id: Deprecated (use :attr:`account_id` instead).
50
+ :param str refresh_token: Token to be used to acquire new access token when existing one
51
+ expires.
52
+ :param expiration: Either the number of seconds from now that the token expires in or the
53
+ datetime at which the token expires.
54
+ :type expiration: int or datetime
55
+ :param list scope: List of scopes to request in base oauth flow.
61
56
"""
62
57
self .access_token = access_token
63
58
if not expiration :
@@ -84,17 +79,15 @@ def __repr__(self):
84
79
85
80
class OAuth2FlowResult (OAuth2FlowNoRedirectResult ):
86
81
"""
87
- Authorization information for an OAuth2Flow with redirect.
82
+ Authorization information for an :class:` OAuth2Flow` with redirect.
88
83
"""
89
84
90
85
def __init__ (self , access_token , account_id , user_id , url_state , refresh_token ,
91
86
expires_in , scope ):
92
87
"""
93
- Same as OAuth2FlowNoRedirectResult but with url_state.
88
+ Same as :class:` OAuth2FlowNoRedirectResult` but with url_state.
94
89
95
- Args:
96
- url_state (str): The url state that was set by
97
- :meth:`DropboxOAuth2Flow.start`.
90
+ :param str url_state: The url state that was set by :meth:`DropboxOAuth2Flow.start`.
98
91
"""
99
92
super (OAuth2FlowResult , self ).__init__ (
100
93
access_token = access_token ,
@@ -234,9 +227,8 @@ def _finish(self, code, redirect_uri, code_verifier):
234
227
def build_path (self , target , params = None ):
235
228
"""Build the path component for an API URL.
236
229
237
- This method urlencodes the parameters, adds them
238
- to the end of the target url, and puts a marker for the API
239
- version in front.
230
+ This method urlencodes the parameters, adds them to the end of the target url, and puts a
231
+ marker for the API version in front.
240
232
241
233
:param str target: A target url (e.g. '/files') to build upon.
242
234
:param dict params: Optional dictionary of parameters (name to value).
@@ -263,8 +255,7 @@ def build_path(self, target, params=None):
263
255
def build_url (self , target , params = None , host = API_HOST ):
264
256
"""Build an API URL.
265
257
266
- This method adds scheme and hostname to the path
267
- returned from build_path.
258
+ This method adds scheme and hostname to the path returned from build_path.
268
259
269
260
:param str target: A target url (e.g. '/files') to build upon.
270
261
:param dict params: Optional dictionary of parameters (name to value).
@@ -279,7 +270,8 @@ class DropboxOAuth2FlowNoRedirect(DropboxOAuth2FlowBase):
279
270
OAuth 2 authorization helper for apps that can't provide a redirect URI
280
271
(such as the command-line example apps).
281
272
282
- See examples under example/oauth
273
+ See examples under `example/oauth <https://github.com/dropbox/dropbox-sdk-python/tree/master/
274
+ example/oauth>`_
283
275
284
276
"""
285
277
@@ -290,33 +282,31 @@ def __init__(self, consumer_key, consumer_secret=None, locale=None, token_access
290
282
291
283
:param str consumer_key: Your API app's "app key".
292
284
:param str consumer_secret: Your API app's "app secret".
293
- :param str locale: The locale of the user of your application. For
294
- example "en" or "en_US". Some API calls return localized data and
295
- error messages; this setting tells the server which locale to use.
296
- By default, the server uses "en_US".
285
+ :param str locale: The locale of the user of your application. For example "en" or "en_US".
286
+ Some API calls return localized data and error messages; this setting tells the server
287
+ which locale to use. By default, the server uses "en_US".
297
288
:param str token_access_type: the type of token to be requested.
298
289
From the following enum:
299
290
300
291
* legacy - creates one long-lived token with no expiration
301
292
* online - create one short-lived token with an expiration
302
293
* offline - create one short-lived token with an expiration with a refresh token
303
294
304
- :param list scope: list of scopes to request in base oauth flow. If left blank,
305
- will default to all scopes for app.
306
- :param str include_granted_scopes: which scopes to include from previous grants
295
+ :param list scope: list of scopes to request in base oauth flow.
296
+ If left blank, will default to all scopes for app.
297
+ :param str include_granted_scopes: which scopes to include from previous grants.
307
298
From the following enum:
308
299
309
300
* user - include user scopes in the grant
310
301
* team - include team scopes in the grant
311
- * Note: if this user has never linked the app, include_granted_scopes must be None
302
+ * * Note* : if this user has never linked the app, include_granted_scopes must be None
312
303
313
304
:param bool use_pkce: Whether or not to use Sha256 based PKCE. PKCE should be only use on
314
305
client apps which doesn't call your server. It is less secure than non-PKCE flow but
315
306
can be used if you are unable to safely retrieve your app secret.
316
307
:param Optional[float] timeout: Maximum duration in seconds that
317
- client will wait for any single packet from the
318
- server. After the timeout the client will give up on
319
- connection. If `None`, client will wait forever. Defaults
308
+ client will wait for any single packet from the server. After the timeout the client
309
+ will give up on connection. If `None`, client will wait forever. Defaults
320
310
to 100 seconds.
321
311
"""
322
312
super (DropboxOAuth2FlowNoRedirect , self ).__init__ (
@@ -334,10 +324,9 @@ def start(self):
334
324
"""
335
325
Starts the OAuth 2 authorization process.
336
326
337
- :return: The URL for a page on Dropbox's website. This page will let
338
- the user "approve" your app, which gives your app permission to
339
- access the user's Dropbox account. Tell the user to visit this URL
340
- and approve your app.
327
+ :return: The URL for a page on Dropbox's website. This page will let the user "approve"
328
+ your app, which gives your app permission to access the user's Dropbox account.
329
+ Tell the user to visit this URL and approve your app.
341
330
"""
342
331
return self ._get_authorize_url (None , None , self .token_access_type ,
343
332
scope = self .scope ,
@@ -346,27 +335,27 @@ def start(self):
346
335
347
336
def finish (self , code ):
348
337
"""
349
- If the user approves your app, they will be presented with an
350
- "authorization code". Have the user copy/paste that authorization code
351
- into your app and then call this method to get an access token.
338
+ If the user approves your app, they will be presented with an "authorization code".
339
+ Have the user copy/paste that authorization code into your app and then call this method to
340
+ get an access token.
352
341
353
342
:param str code: The authorization code shown to the user when they
354
343
approved your app.
355
- :rtype: OAuth2FlowNoRedirectResult
344
+ :rtype: :class:` OAuth2FlowNoRedirectResult`
356
345
:raises: The same exceptions as :meth:`DropboxOAuth2Flow.finish()`.
357
346
"""
358
347
return self ._finish (code , None , self .code_verifier )
359
348
360
349
361
350
class DropboxOAuth2Flow (DropboxOAuth2FlowBase ):
362
351
"""
363
- OAuth 2 authorization helper. Use this for web apps.
352
+ OAuth 2 authorization helper. Use this for web apps.
364
353
365
- OAuth 2 has a two-step authorization process. The first step is having the
366
- user authorize your app. The second involves getting an OAuth 2 access
367
- token from Dropbox.
354
+ OAuth 2 has a two-step authorization process. The first step is having the user authorize your
355
+ app. The second involves getting an OAuth 2 access token from Dropbox.
368
356
369
- See examples under example/oauth
357
+ See examples under `example/oauth <https://github.com/dropbox/dropbox-sdk-python/tree/master/
358
+ example/oauth>`_
370
359
371
360
"""
372
361
@@ -379,41 +368,38 @@ def __init__(self, consumer_key, redirect_uri, session,
379
368
380
369
:param str consumer_key: Your API app's "app key".
381
370
:param str consumer_secret: Your API app's "app secret".
382
- :param str redirect_uri: The URI that the Dropbox server will redirect
383
- the user to after the user finishes authorizing your app. This URI
384
- must be HTTPS-based and pre-registered with the Dropbox servers,
385
- though localhost URIs are allowed without pre-registration and can
386
- be either HTTP or HTTPS.
387
- :param dict session: A dict-like object that represents the current
388
- user's web session (will be used to save the CSRF token).
389
- :param str csrf_token_session_key: The key to use when storing the CSRF
390
- token in the session (for example: "dropbox-auth-csrf-token").
391
- :param str locale: The locale of the user of your application. For
392
- example "en" or "en_US". Some API calls return localized data and
393
- error messages; this setting tells the server which locale to use.
394
- By default, the server uses "en_US".
395
- :param str token_access_type: the type of token to be requested.
371
+ :param str redirect_uri: The URI that the Dropbox server will redirect the user to after the
372
+ user finishes authorizing your app. This URI must be HTTPS-based and pre-registered
373
+ with the Dropbox servers, though localhost URIs are allowed without pre-registration and
374
+ can be either HTTP or HTTPS.
375
+ :param dict session: A dict-like object that represents the current user's web session
376
+ (Will be used to save the CSRF token).
377
+ :param str csrf_token_session_key: The key to use when storing the CSRF token in the session
378
+ (For example: "dropbox-auth-csrf-token").
379
+ :param str locale: The locale of the user of your application. For example "en" or "en_US".
380
+ Some API calls return localized data and error messages; this setting tells the server
381
+ which locale to use. By default, the server uses "en_US".
382
+ :param str token_access_type: The type of token to be requested.
396
383
From the following enum:
397
384
398
385
* legacy - creates one long-lived token with no expiration
399
386
* online - create one short-lived token with an expiration
400
387
* offline - create one short-lived token with an expiration with a refresh token
401
388
402
- :param list scope: list of scopes to request in base oauth flow. If left blank,
389
+ :param list scope: List of scopes to request in base oauth flow. If left blank,
403
390
will default to all scopes for app.
404
- :param str include_granted_scopes: which scopes to include from previous grants
391
+ :param str include_granted_scopes: Which scopes to include from previous grants.
405
392
From the following enum:
406
393
407
394
* user - include user scopes in the grant
408
395
* team - include team scopes in the grant
409
- * Note: if this user has never linked the app, include_granted_scopes must be None
396
+ * *Note*: If this user has never linked the app, :attr:`include_granted_scopes` must \
397
+ be `None`
410
398
411
399
:param bool use_pkce: Whether or not to use Sha256 based PKCE
412
- :param Optional[float] timeout: Maximum duration in seconds that
413
- client will wait for any single packet from the
414
- server. After the timeout the client will give up on
415
- connection. If `None`, client will wait forever. Defaults
416
- to 100 seconds.
400
+ :param Optional[float] timeout: Maximum duration in seconds that client will wait for any
401
+ single packet from the server. After the timeout the client will give up on connection.
402
+ If `None`, client will wait forever. Defaults to 100 seconds.
417
403
"""
418
404
419
405
super (DropboxOAuth2Flow , self ).__init__ (
@@ -434,24 +420,19 @@ def start(self, url_state=None):
434
420
"""
435
421
Starts the OAuth 2 authorization process.
436
422
437
- This function builds an "authorization URL". You should redirect your
438
- user's browser to this URL, which will give them an opportunity to
439
- grant your app access to their Dropbox account. When the user
440
- completes this process, they will be automatically redirected to the
441
- ``redirect_uri`` you passed in to the constructor.
442
-
443
- This function will also save a CSRF token to
444
- ``session[csrf_token_session_key]`` (as provided to the constructor).
445
- This CSRF token will be checked on :meth:`finish()` to prevent request
446
- forgery.
447
-
448
- :param str url_state: Any data that you would like to keep in the URL
449
- through the authorization process. This exact value will be
450
- returned to you by :meth:`finish()`.
451
- :return: The URL for a page on Dropbox's website. This page will let
452
- the user "approve" your app, which gives your app permission to
453
- access the user's Dropbox account. Tell the user to visit this URL
454
- and approve your app.
423
+ This function builds an "authorization URL". You should redirect your user's browser to this
424
+ URL, which will give them an opportunity to grant your app access to their Dropbox
425
+ account. When the user completes this process, they will be automatically redirected to
426
+ the :attr:`redirect_uri` you passed in to the constructor. This function will also save
427
+ a CSRF token to :attr:`session[csrf_token_session_key]`
428
+ (as provided to the constructor). This CSRF token will be checked on :meth:`finish()`
429
+ to prevent request forgery.
430
+
431
+ :param str url_state: Any data that you would like to keep in the URL through the
432
+ authorization process. This exact value will be returned to you by :meth:`finish()`.
433
+ :return: The URL for a page on Dropbox's website. This page will let the user "approve" your
434
+ app, which gives your app permission to access the user's Dropbox account. Tell the user
435
+ to visit this URL and approve your app.
455
436
"""
456
437
csrf_token = base64 .urlsafe_b64encode (os .urandom (16 )).decode ('ascii' )
457
438
state = csrf_token
@@ -466,23 +447,19 @@ def start(self, url_state=None):
466
447
467
448
def finish (self , query_params ):
468
449
"""
469
- Call this after the user has visited the authorize URL (see
470
- :meth:`start()`), approved your app and was redirected to your redirect
471
- URI.
472
-
473
- :param dict query_params: The query parameters on the GET request to
474
- your redirect URI.
475
- :rtype: OAuth2FlowResult
476
- :raises: :class:`BadRequestException` If the redirect URL was missing
477
- parameters or if the given parameters were not valid.
478
- :raises: :class:`BadStateException` If there's no CSRF token in the
479
- session.
480
- :raises: :class:`CsrfException` If the ``state`` query parameter
481
- doesn't contain the CSRF token from the user's session.
482
- :raises: :class:`NotApprovedException` If the user chose not to
483
- approve your app.
484
- :raises: :class:`ProviderException` If Dropbox redirected to your
485
- redirect URI with some unexpected error identifier and error message.
450
+ Call this after the user has visited the authorize URL (see :meth:`start()`), approved your
451
+ app and was redirected to your redirect URI.
452
+
453
+ :param dict query_params: The query parameters on the GET request to your redirect URI.
454
+ :rtype: class:`OAuth2FlowResult`
455
+ :raises: :class:`BadRequestException` If the redirect URL was missing parameters or if the
456
+ given parameters were not valid.
457
+ :raises: :class:`BadStateException` If there's no CSRF token in the session.
458
+ :raises: :class:`CsrfException` If the :attr:`state` query parameter doesn't contain the
459
+ CSRF token from the user's session.
460
+ :raises: :class:`NotApprovedException` If the user chose not to approve your app.
461
+ :raises: :class:`ProviderException` If Dropbox redirected to your redirect URI with some
462
+ unexpected error identifier and error message.
486
463
"""
487
464
# Check well-formedness of request.
488
465
@@ -553,8 +530,7 @@ def finish(self, query_params):
553
530
554
531
class BadRequestException (Exception ):
555
532
"""
556
- Thrown if the redirect URL was missing parameters or if the
557
- given parameters were not valid.
533
+ Thrown if the redirect URL was missing parameters or if the given parameters were not valid.
558
534
559
535
The recommended action is to show an HTTP 400 error page.
560
536
"""
@@ -563,19 +539,18 @@ class BadRequestException(Exception):
563
539
564
540
class BadStateException (Exception ):
565
541
"""
566
- Thrown if all the parameters are correct, but there's no CSRF token in the
567
- session. This probably means that the session expired.
542
+ Thrown if all the parameters are correct, but there's no CSRF token in the session. This
543
+ probably means that the session expired.
568
544
569
- The recommended action is to redirect the user's browser to try the
570
- approval process again.
545
+ The recommended action is to redirect the user's browser to try the approval process again.
571
546
"""
572
547
pass
573
548
574
549
575
550
class CsrfException (Exception ):
576
551
"""
577
- Thrown if the given 'state' parameter doesn't contain the CSRF token from
578
- the user's session. This is blocked to prevent CSRF attacks.
552
+ Thrown if the given 'state' parameter doesn't contain the CSRF token from the user's session.
553
+ This is blocked to prevent CSRF attacks.
579
554
580
555
The recommended action is to respond with an HTTP 403 error page.
581
556
"""
@@ -591,11 +566,10 @@ class NotApprovedException(Exception):
591
566
592
567
class ProviderException (Exception ):
593
568
"""
594
- Dropbox redirected to your redirect URI with some unexpected error
595
- identifier and error message.
569
+ Dropbox redirected to your redirect URI with some unexpected error identifier and error message.
596
570
597
- The recommended action is to log the error, tell the user something went
598
- wrong, and let them try again.
571
+ The recommended action is to log the error, tell the user something went wrong, and let them try
572
+ again.
599
573
"""
600
574
pass
601
575
@@ -621,11 +595,11 @@ def _safe_equals(a, b):
621
595
622
596
def _params_to_urlencoded (params ):
623
597
"""
624
- Returns a application/x-www-form-urlencoded `` str`` representing the
625
- key/value pairs in `` params` `.
598
+ Returns a application/x-www-form-urlencoded :class:` str` representing the key/value pairs in
599
+ :attr:` params`.
626
600
627
- Keys are values are ``str()``'d before calling `` urllib.urlencode`` , with
628
- the exception of unicode objects which are utf8-encoded.
601
+ Keys are values are ``str()``'d before calling :meth:` urllib.urlencode`, with the exception of
602
+ unicode objects which are utf8-encoded.
629
603
"""
630
604
def encode (o ):
631
605
if isinstance (o , six .binary_type ):
0 commit comments