@@ -156,6 +156,7 @@ def __init__(self):
156
156
self .tokens = {}
157
157
self .tokenExpiry = {}
158
158
self .tokenFile = None
159
+ self .hasUserPwd = False
159
160
self .msgsHost = self .API_MSGSHOST
160
161
self .sess = requests .Session ()
161
162
self .endpoints = {"self" : SkypeEndpoint (self , "SELF" )}
@@ -170,6 +171,23 @@ def connected(self):
170
171
def guest (self ):
171
172
return self .userId .startswith ("guest:" ) if self .userId else None
172
173
174
+ def closure (self , method , * args , ** kwargs ):
175
+ """
176
+ Create a generic closure to call a method with fixed arguments.
177
+
178
+ Args:
179
+ method (MethodType): bound method of the class
180
+ args (list): positional arguments for the method
181
+ kwargs (dict): keyword arguments for the method
182
+
183
+ Returns:
184
+ MethodType: bound method closure
185
+ """
186
+ @functools .wraps (method )
187
+ def inner (self ):
188
+ return method (* args , ** kwargs )
189
+ return MethodType (inner , self )
190
+
173
191
def __call__ (self , method , url , codes = (200 , 201 , 202 , 204 , 207 ), auth = None , headers = None , ** kwargs ):
174
192
"""
175
193
Make an API call. Most parameters are passed directly to :mod:`requests`.
@@ -253,19 +271,6 @@ def syncStateCall(self, method, url, params={}, **kwargs):
253
271
states .append (state )
254
272
return resp
255
273
256
- def setUserPwd (self , user , pwd ):
257
- """
258
- Replace the stub :meth:`getSkypeToken` method with one that connects via the Microsoft account flow using the
259
- given credentials. Avoids storing the account password in an accessible way.
260
-
261
- Args:
262
- user (str): username or email address of the connecting account
263
- pwd (str): password of the connecting account
264
- """
265
- def getSkypeToken (self ):
266
- self .soapLogin (user , pwd )
267
- self .getSkypeToken = MethodType (getSkypeToken , self )
268
-
269
274
def setTokenFile (self , path ):
270
275
"""
271
276
Enable reading and writing session tokens to a file at the given location.
@@ -345,6 +350,25 @@ def verifyToken(self, auth):
345
350
if "reg" not in self .tokenExpiry or datetime .now () >= self .tokenExpiry ["reg" ]:
346
351
self .getRegToken ()
347
352
353
+ def skypeTokenClosure (self , method , * args , ** kwargs ):
354
+ """
355
+ Replace the stub :meth:`getSkypeToken` method with one that connects using the given credentials. Avoids
356
+ storing the account password in an accessible way.
357
+ """
358
+ self .getSkypeToken = self .closure (method , * args , ** kwargs )
359
+ self .hasUserPwd = True
360
+
361
+ def setUserPwd (self , user , pwd ):
362
+ """
363
+ Replace the stub :meth:`getSkypeToken` method with one that connects via SOAP login using the given
364
+ credentials. Avoids storing the account password in an accessible way.
365
+
366
+ Args:
367
+ user (str): username or email address of the connecting account
368
+ pwd (str): password of the connecting account
369
+ """
370
+ self .skypeTokenClosure (self .soapLogin , user , pwd )
371
+
348
372
def liveLogin (self , user , pwd ):
349
373
"""
350
374
Obtain connection parameters from the Microsoft account login page, and perform a login with the given email
@@ -365,6 +389,8 @@ def liveLogin(self, user, pwd):
365
389
.SkypeAuthException: if the login request is rejected
366
390
.SkypeApiException: if the login form can't be processed
367
391
"""
392
+ if not self .hasUserPwd :
393
+ self .skypeTokenClosure (self .liveLogin , user , pwd )
368
394
self .tokens ["skype" ], self .tokenExpiry ["skype" ] = SkypeLiveAuthProvider (self ).auth (user , pwd )
369
395
self .getUserId ()
370
396
self .getRegToken ()
@@ -390,6 +416,8 @@ def soapLogin(self, user, pwd):
390
416
.SkypeAuthException: if the login request is rejected
391
417
.SkypeApiException: if the login form can't be processed
392
418
"""
419
+ if not self .hasUserPwd :
420
+ self .skypeTokenClosure (self .soapLogin , user , pwd )
393
421
self .tokens ["skype" ], self .tokenExpiry ["skype" ] = SkypeSOAPAuthProvider (self ).auth (user , pwd )
394
422
self .getUserId ()
395
423
self .getRegToken ()
0 commit comments