11from abc import ABC , abstractmethod
22from typing import Iterable
33
4- from oauthlib .oauth2 import BackendApplicationClient
54from requests_oauthlib import OAuth2Session
65
76from pardner .verticals .base import Vertical
@@ -27,18 +26,14 @@ def __init__(
2726 )
2827
2928
30- class BaseTransferService (OAuth2Session , ABC ):
29+ class BaseTransferService (ABC ):
3130 """
3231 A base class to be extended by service-specific classes that implement logic for
3332 OAuth 2.0 and data transfers.
34-
35- :param client_id: Client identifier given by the OAuth provider upon registration.
36- :param client_secret: The `client_secret` paired to the `client_id`.
37- :param redirect_url: The registered callback URI.
3833 """
3934
4035 _client_secret : str
41- _scope : set [ str ] = set ()
36+ _oAuth2Session : OAuth2Session
4237 _service_name : str
4338 _supported_verticals : set [Vertical ] = set ()
4439 _verticals : set [Vertical ] = set ()
@@ -52,11 +47,20 @@ def __init__(
5247 supported_verticals : set [Vertical ],
5348 verticals : set [Vertical ] = set (),
5449 ) -> None :
55- background_application_client = BackendApplicationClient (client_id )
56- super ().__init__ (
57- client_id = client_id ,
58- client = background_application_client ,
59- redirect_uri = redirect_uri ,
50+ """
51+ Initializes an instance of BaseTransferService, which shouldn't be done unless
52+ by classes that extend it.
53+
54+ :param service_name: Name of the service for which the transfer is being built.
55+ :param client_id: Client identifier given by the OAuth provider upon registration.
56+ :param client_secret: The `client_secret` paired to the `client_id`.
57+ :param redirect_uri: The registered callback URI.
58+ :param supported_verticals: The `Vertical`s that can be fetched on the service.
59+ :param verticals: The `Vertical`s for which the transfer service has
60+ appropriate scope to fetch.
61+ """
62+ self ._oAuth2Session = OAuth2Session (
63+ client_id = client_id , redirect_uri = redirect_uri
6064 )
6165 self ._client_secret = client_secret
6266 self ._supported_verticals = supported_verticals
@@ -67,6 +71,14 @@ def __init__(
6771 def name (self ) -> str :
6872 return self ._service_name
6973
74+ @property
75+ def scope (self ) -> set [str ]:
76+ return self ._oAuth2Session .scope if self ._oAuth2Session .scope else set ()
77+
78+ @scope .setter
79+ def scope (self , new_scope : Iterable [str ]) -> None :
80+ self ._oAuth2Session .scope = set (new_scope )
81+
7082 @property
7183 def verticals (self ) -> set [Vertical ]:
7284 return self ._verticals
@@ -110,7 +122,7 @@ def add_verticals(
110122 raise InsufficientScopeException (verticals , self .name )
111123 elif not new_scopes .issubset (original_scopes ):
112124 self .verticals = new_verticals | self .verticals
113- del self .access_token
125+ del self ._oAuth2Session . access_token
114126 self .scope = original_scopes | new_scopes
115127 return False
116128
0 commit comments