@@ -595,6 +595,9 @@ def getToken(self, t):
595
595
596
596
597
597
class SkypeSOAPAuthProvider (SkypeAuthProvider ):
598
+ """
599
+ An authentication provider that connects via Microsoft account SOAP authentication.
600
+ """
598
601
599
602
template = """
600
603
<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'
@@ -631,6 +634,27 @@ class SkypeSOAPAuthProvider(SkypeAuthProvider):
631
634
def encode (value ):
632
635
return value .replace ("&" , "&" ).replace ("<" , "<" ).replace (">" , ">" )
633
636
637
+ def auth (self , user , pwd ):
638
+ """
639
+ Perform a SOAP login with the given email address or Skype username, and its password.
640
+
641
+ .. note::
642
+ Microsoft accounts with two-factor authentication enabled must provide an application-specific password.
643
+
644
+ Args:
645
+ user (str): username or email address of the connecting account
646
+ pwd (str): password of the connecting account
647
+
648
+ Returns:
649
+ (str, datetime.datetime) tuple: Skype token, and associated expiry if known
650
+
651
+ Raises:
652
+ .SkypeAuthException: if the login request is rejected
653
+ .SkypeApiException: if the login form can't be processed
654
+ """
655
+ token = self .getSecToken (user , pwd )
656
+ return self .exchangeToken (token )
657
+
634
658
def getSecToken (self , user , pwd ):
635
659
loginResp = self .conn ("POST" , "{0}/RST.srf" .format (SkypeConnection .API_MSACC ),
636
660
data = self .template .format (self .encode (user ), self .encode (pwd )))
@@ -646,11 +670,14 @@ def getSecToken(self, user, pwd):
646
670
code = fnode .text
647
671
elif ftag == "faultstring" :
648
672
msg = fnode .text
649
- raise SkypeAuthException ("{} - {}" .format (code , msg ), loginResp )
673
+ if code or msg :
674
+ raise SkypeAuthException ("{} - {}" .format (code , msg ), loginResp )
675
+ else :
676
+ raise SkypeApiException ("Unknown fault whilst requesting security token" , loginResp )
650
677
elif tag == "BinarySecurityToken" :
651
678
token = node .text
652
679
if not token :
653
- raise SkypeAuthException ("Couldn't retrieve security token from login response" , loginResp )
680
+ raise SkypeApiException ("Couldn't retrieve security token from login response" , loginResp )
654
681
return token
655
682
656
683
def exchangeToken (self , token ):
@@ -659,7 +686,7 @@ def exchangeToken(self, token):
659
686
try :
660
687
edgeData = edgeResp .json ()
661
688
except ValueError :
662
- raise SkypeAuthException ("Couldn't parse edge response body" , edgeResp )
689
+ raise SkypeApiException ("Couldn't parse edge response body" , edgeResp )
663
690
if "skypetoken" in edgeData :
664
691
token = edgeData ["skypetoken" ]
665
692
expiry = None
@@ -668,13 +695,9 @@ def exchangeToken(self, token):
668
695
return (token , expiry )
669
696
elif "status" in edgeData :
670
697
status = edgeData ["status" ]
671
- raise SkypeAuthException ("{} - {}" .format (status .get ("code" ), status .get ("text" )), edgeResp )
698
+ raise SkypeApiException ("{} - {}" .format (status .get ("code" ), status .get ("text" )), edgeResp )
672
699
else :
673
- raise SkypeAuthException ("Couldn't retrieve token from edge response" , edgeResp )
674
-
675
- def auth (self , user , pwd ):
676
- token = self .getSecToken (user , pwd )
677
- return self .exchangeToken (token )
700
+ raise SkypeApiException ("Couldn't retrieve token from edge response" , edgeResp )
678
701
679
702
680
703
class SkypeGuestAuthProvider (SkypeAuthProvider ):
0 commit comments