Skip to content

Commit 3b0f419

Browse files
authored
Merge pull request #74 from lumapps/feat/getToken_wrapper
Feat/getToken wrapper
2 parents 74fbf45 + 1c09484 commit 3b0f419

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lumapps/api/client.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,28 @@ def _prune(self, method_parts, content):
187187
pop_matches(pth, content)
188188
return content
189189

190-
def get_new_client_as(self, user):
191-
return ApiClient(self._auth_info, self.api_info, user=user)
190+
def get_new_client_as_using_dwd(self, user_email):
191+
""" Get a new ApiClient using domain-wide delegation """
192+
return ApiClient(self._auth_info, self.api_info, user=user_email)
193+
194+
def get_new_client_as(self, user_email, customer_id=None):
195+
""" Get a new ApiClient using an authorized service account by obtaining a
196+
token using the user/getToken method.
197+
198+
Args:
199+
user_email (str): User you want to authenticate on behalf of
200+
customer_id (str): Id of the LumApps customer the user belong to
201+
202+
Returns:
203+
ApiClient: A new instance of the ApiClient correctly authenticated.
204+
"""
205+
if not self.creds:
206+
raise Exception("No credentials (auth_info) provided")
207+
token_infos = self.get_call(
208+
"user/getToken", customerId=customer_id, email=user_email
209+
)
210+
token = token_infos["accessToken"]
211+
return ApiClient(api_info=self.api_info, token=token, user=user_email)
192212

193213
@property
194214
def token(self):

0 commit comments

Comments
 (0)