1212from google .oauth2 .credentials import Credentials
1313from google .oauth2 .service_account import Credentials as SvcCredentials
1414from google_auth_oauthlib .flow import InstalledAppFlow
15+ from scubagoggles .scuba_constants import API_SCOPES
1516
1617# The class is worth it just for the encapsulation. It allows the potential
1718# of credential refresh multiple times, which may be beneficial during a
@@ -24,17 +25,6 @@ class GwsAuth:
2425 """Generates an Oauth token for accessing Google's APIs
2526 """
2627
27- _base_auth_url = 'https://www.googleapis.com/auth'
28-
29- _scopes = (f'{ _base_auth_url } /admin.reports.audit.readonly' ,
30- f'{ _base_auth_url } /admin.directory.domain.readonly' ,
31- f'{ _base_auth_url } /admin.directory.orgunit.readonly' ,
32- f'{ _base_auth_url } /admin.directory.user.readonly' ,
33- f'{ _base_auth_url } /admin.directory.group.readonly' ,
34- f'{ _base_auth_url } /admin.directory.customer.readonly' ,
35- f'{ _base_auth_url } /apps.groups.settings' ,
36- f'{ _base_auth_url } /cloud-identity.policies.readonly' )
37-
3828 def __init__ (self , credentials_path : Path , svc_account_email : str = None ):
3929 """GwsAuth class initialization.
4030
@@ -61,7 +51,7 @@ def __init__(self, credentials_path: Path, svc_account_email: str = None):
6151 if svc_account_email :
6252 get_credentials = SvcCredentials .from_service_account_file
6353 self ._token = get_credentials (str (credentials_path ),
64- scopes = self . _scopes ,
54+ scopes = API_SCOPES ,
6555 subject = svc_account_email )
6656 return
6757
@@ -79,7 +69,7 @@ def __init__(self, credentials_path: Path, svc_account_email: str = None):
7969 # have worked when no browser was available).
8070 credentials_file = str (self ._credentials_path )
8171 flow = InstalledAppFlow .from_client_secrets_file (credentials_file ,
82- self . _scopes )
72+ API_SCOPES )
8373
8474 try :
8575 self ._token = flow .run_local_server (
@@ -116,7 +106,7 @@ def _check_scopes(self):
116106 token = json .load (in_stream )
117107
118108 token_scopes = frozenset (token ['scopes' ])
119- valid_scopes = frozenset (self . _scopes )
109+ valid_scopes = frozenset (API_SCOPES )
120110
121111 # Delete the token file if its scopes don't match those defined in
122112 # this class. The token file will be recreated in the constructor
@@ -145,7 +135,7 @@ def _load_token(self):
145135 # refresh the token if it has expired.
146136 token_file = str (self ._token_path )
147137 self ._token = Credentials .from_authorized_user_file (token_file ,
148- self . _scopes )
138+ API_SCOPES )
149139
150140 self ._refresh_token ()
151141
0 commit comments