-
Notifications
You must be signed in to change notification settings - Fork 214
/
remote_managed_oauth2.py
38 lines (31 loc) · 1.18 KB
/
remote_managed_oauth2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding: utf-8
from __future__ import unicode_literals
from .oauth2 import OAuth2
class RemoteOAuth2Mixin(OAuth2):
"""
Box SDK OAuth2 mixin.
Allows for storing auth tokens remotely.
"""
def __init__(self, retrieve_access_token=None, *args, **kwargs):
"""
:param retrieve_access_token:
Callback to exchange an existing access token for a new one.
:type retrieve_access_token:
`callable` of `unicode` => `unicode`
"""
# pylint:disable=keyword-arg-before-vararg
self._retrieve_access_token = retrieve_access_token
super(RemoteOAuth2Mixin, self).__init__(*args, **kwargs)
def _refresh(self, access_token):
"""
Base class override. Ask the remote host for a new token.
"""
self._access_token = self._retrieve_access_token(access_token)
return self._access_token, None
class RemoteOAuth2(RemoteOAuth2Mixin):
"""
Box SDK OAuth2 subclass.
Allows for storing auth tokens remotely. The retrieve_access_token callback should
return an access token, presumably acquired from a remote server on which your auth credentials are available.
"""
pass