def dsid_factory(uname, passwd):
resp = None
req = urllib2.Request("https://setup.icloud.com/setup/authenticate/%s" % uname)
req.add_header('Authorization', 'Basic %s' % base64.b64encode("%s:%s" % (uname, passwd)))
req.add_header('Content-Type', 'application/json')
try:
resp = urllib2.urlopen(req)
except urllib2.HTTPError as e:
if e.code != 200:
if e.code == 401:
return (False, "HTTP Error 401: Unauthorized. Are you sure the credentials are correct?\n", False)
elif e.code == 409:
tokenLocal = tokenRead()
if tokenLocal != False: #if we have token use it ... bc 2SV wont work with regular uname/passw
dsid = tokenLocal.split("\n")[1].split(":")[0]
tokz = tokenLocal.split("\n")[1].split(":")[1]
return (dsid, tokz, True)
else:
return (False, "HTTP Error 409: Conflict. 2 Factor Authentication appears to be enabled. You cannot use this function unless you get your MMeAuthToken manually (generated either on your PC/Mac or on your iOS device).\n", False)
elif e.code == 404:
return (False, "HTTP Error 404: URL not found. Did you enter a username?\n", False)
else:
return (False, "HTTP Error %s." % e.code, False)
else:
return e
content = resp.read()
uname = plistlib.readPlistFromString(content)["appleAccountInfo"]["dsPrsID"] #stitch our own auth DSID
passwd = plistlib.readPlistFromString(content)["tokens"]["mmeAuthToken"] #stitch with token
return (uname, passwd, False) #third value is "usingToken?"
评论列表
文章目录