Added service specific log in
This commit is contained in:
parent
285a114a64
commit
9190c62a80
1 changed files with 38 additions and 2 deletions
|
@ -260,7 +260,7 @@ class PyiCloudService(object):
|
||||||
self._files = None
|
self._files = None
|
||||||
self._photos = None
|
self._photos = None
|
||||||
|
|
||||||
def authenticate(self, force_refresh=False):
|
def authenticate(self, force_refresh=False, service=None):
|
||||||
"""
|
"""
|
||||||
Handles authentication, and persists cookies so that
|
Handles authentication, and persists cookies so that
|
||||||
subsequent logins will not cause additional e-mails from Apple.
|
subsequent logins will not cause additional e-mails from Apple.
|
||||||
|
@ -273,10 +273,19 @@ class PyiCloudService(object):
|
||||||
req = self.session.post("%s/validate" % self.SETUP_ENDPOINT, data="null")
|
req = self.session.post("%s/validate" % self.SETUP_ENDPOINT, data="null")
|
||||||
LOGGER.debug("Session token is still valid")
|
LOGGER.debug("Session token is still valid")
|
||||||
self.data = req.json()
|
self.data = req.json()
|
||||||
|
LOGGER.debug(req.json())
|
||||||
login_successful = True
|
login_successful = True
|
||||||
except PyiCloudAPIResponseException:
|
except PyiCloudAPIResponseException:
|
||||||
LOGGER.debug("Invalid authentication token, will log in from scratch.")
|
LOGGER.debug("Invalid authentication token, will log in from scratch.")
|
||||||
|
|
||||||
|
if not login_successful and service != None:
|
||||||
|
LOGGER.debug("Authenticating as %s for %s" % (self.user["accountName"], service))
|
||||||
|
try:
|
||||||
|
self._authenticate_with_credentials_service(service)
|
||||||
|
login_successful = True
|
||||||
|
except:
|
||||||
|
LOGGER.debug("Could not log into service. Attempting brand new login.")
|
||||||
|
|
||||||
if not login_successful:
|
if not login_successful:
|
||||||
LOGGER.debug("Authenticating as %s" % self.user["accountName"])
|
LOGGER.debug("Authenticating as %s" % self.user["accountName"])
|
||||||
|
|
||||||
|
@ -302,6 +311,11 @@ class PyiCloudService(object):
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
headers=headers,
|
headers=headers,
|
||||||
)
|
)
|
||||||
|
LOGGER.debug(req.headers)
|
||||||
|
try:
|
||||||
|
LOGGER.debug(req.json())
|
||||||
|
except:
|
||||||
|
LOGGER.debug(req)
|
||||||
except PyiCloudAPIResponseException as error:
|
except PyiCloudAPIResponseException as error:
|
||||||
msg = "Invalid email/password combination."
|
msg = "Invalid email/password combination."
|
||||||
raise PyiCloudFailedLoginException(msg, error)
|
raise PyiCloudFailedLoginException(msg, error)
|
||||||
|
@ -325,11 +339,33 @@ class PyiCloudService(object):
|
||||||
req = self.session.post(
|
req = self.session.post(
|
||||||
"%s/accountLogin" % self.SETUP_ENDPOINT, data=json.dumps(data)
|
"%s/accountLogin" % self.SETUP_ENDPOINT, data=json.dumps(data)
|
||||||
)
|
)
|
||||||
|
self.data = req.json()
|
||||||
except PyiCloudAPIResponseException as error:
|
except PyiCloudAPIResponseException as error:
|
||||||
msg = "Invalid authentication token."
|
msg = "Invalid authentication token."
|
||||||
raise PyiCloudFailedLoginException(msg, error)
|
raise PyiCloudFailedLoginException(msg, error)
|
||||||
|
|
||||||
self.data = req.json()
|
def _authenticate_with_credentials_service(self, service):
|
||||||
|
"""Authenticate to a specific service using credentials."""
|
||||||
|
data = {
|
||||||
|
"appName": service,
|
||||||
|
"apple_id": self.user["accountName"],
|
||||||
|
"password": self.user["password"]
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
req = self.session.post(
|
||||||
|
"%s/accountLogin" % self.SETUP_ENDPOINT, data=json.dumps(data)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.data = req.json()
|
||||||
|
LOGGER.debug(req.headers)
|
||||||
|
try:
|
||||||
|
LOGGER.debug(req.json())
|
||||||
|
except:
|
||||||
|
LOGGER.debug(req)
|
||||||
|
except PyiCloudAPIResponseException as error:
|
||||||
|
msg = "Invalid email/password combination."
|
||||||
|
raise PyiCloudFailedLoginException(msg, error)
|
||||||
|
|
||||||
def _get_auth_headers(self, overrides=None):
|
def _get_auth_headers(self, overrides=None):
|
||||||
headers = {
|
headers = {
|
||||||
|
|
Loading…
Reference in a new issue