Skip to content

Commit

Permalink
Make gigya authentication region-aware
Browse files Browse the repository at this point in the history
  • Loading branch information
Phype committed Oct 29, 2024
1 parent e021e66 commit 3741eaa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/purei9_unofficial/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

args_cloud.add_argument('-c', "--credentials", type=str, help='elecrolux cloud credentails in username:password format')
args_cloud.add_argument('-t', "--token", type=str, help='electrolux v2 API token')
args_cloud.add_argument("--country", type=str, help='electrolux v2 API token')

cmds_cloud = args_cloud.add_subparsers(help='subcommand, default=status', dest="subcommand")

Expand Down Expand Up @@ -155,7 +156,7 @@ def exiterror(s, parser):
if credentialstore.cloud_email == None and credentialstore.cloud_token_v3 == None:
exiterror("No crentials supplied.", args_cloud)

client = cloudv3.CloudClient(username=credentialstore.cloud_email, password=credentialstore.cloud_passwort, token=credentialstore.cloud_token_v3)
client = cloudv3.CloudClient(username=credentialstore.cloud_email, password=credentialstore.cloud_passwort, token=credentialstore.cloud_token_v3, countrycode=args.country)

credentialstore.save()

Expand Down
31 changes: 26 additions & 5 deletions src/purei9_unofficial/cloudv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,21 @@ def _update(self, command):

class CloudClient:

def __init__(self, username=None, password=None, token=None):
def __init__(self, username=None, password=None, token=None, countrycode=None):

self.client_id = "AEGOneApp"
self.client_secret = "G6PZWyneWAZH6kZePRjZAdBbyyIu3qUgDGUDkat7obfU9ByQSgJPNy8xRo99vzcgWExX9N48gMJo3GWaHbMJsohIYOQ54zH2Hid332UnRZdvWOCWvWNnMNLalHoyH7xU"
self.user_agent = "AEG/2.26 android/10"
self.x_api_key = "PEdfAP7N7sUc95GJPePDU54e2Pybbt6DZtdww7dz"

self.baseurl = "https://api.ocp.electrolux.one"
self.userurl = self.baseurl + "/one-account-user/api/v1"
self.authorizationurl = self.baseurl + "/one-account-authorization/api/v1"
self.authenticationurl = self.baseurl + "/one-account-authentication/api/v1"
self.apiurl = self.baseurl + "/appliance/api/v2"
self.pureapiurl = self.baseurl + "/purei/api/v2"
self.headers = {}
self.countrycode = countrycode

self.username = username
self.password = password
Expand All @@ -217,11 +219,29 @@ def settoken(self, token):
else:
self.token = None

def _getHeaders(self):
def _getHeaders(self, no_login=False):

if not(self.token) or time.time() > self.token["expires"]:
if not(no_login) and (not(self.token) or time.time() > self.token["expires"]):

idToken, countryCode = gigya_login(self.username, self.password)
r = do_http("POST", self.authorizationurl + "/token", json={
"clientId": self.client_id,
"clientSecret": self.client_secret,
"grantType": "client_credentials",
"scope": ""
}, headers={
"x-api-key": self.x_api_key,
"User-Agent": self.user_agent,
"Authorization": "Bearer",
})

self.settoken(r.text)

r = do_http("GET", self.userurl + "/identity-providers?brand=aeg&countryCode=" + self.countrycode,
headers=self._getHeaders(no_login=True))

data = r.json()[0]
self.baseurl = data["httpRegionalBaseUrl"]
idToken, countryCode = gigya_login(self.username, self.password, data["apiKey"], data["domain"])

r = do_http("POST", self.authorizationurl + "/token", json={
"clientId": self.client_id,
Expand All @@ -237,7 +257,8 @@ def _getHeaders(self):
return {
"Authorization": "Bearer " + self.token["accessToken"],
"x-api-key": self.x_api_key,
"User-Agent": self.user_agent
"User-Agent": self.user_agent,
"Context-Brand": "aeg"
}

def tryLogin(self):
Expand Down
9 changes: 4 additions & 5 deletions src/purei9_unofficial/cloudv3_gigya.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ def gigya_print_http(r):
"""
return

def gigya_login(email, password):
def gigya_login(email, password, gigya_apikey, gigya_domain):

gigya_apikey = "4_gqndGblq7WL-gUbN2WzM4A"
gigya_useragent = "okhttp/4.10.0"

r = do_http("POST", "https://socialize.us1.gigya.com/socialize.getIDs", headers={
r = do_http("POST", "https://socialize." + gigya_domain + "/socialize.getIDs", headers={
"apikey": gigya_apikey,
"user-agent": gigya_useragent,
"content-type": "application/x-www-form-urlencoded"
Expand All @@ -101,7 +100,7 @@ def gigya_login(email, password):
gigya_gmid = data["gmid"]
gigya_gcid = data["gcid"]

r = do_http("POST", "https://accounts.us1.gigya.com/accounts.login", headers={
r = do_http("POST", "https://accounts." + gigya_domain + "/accounts.login", headers={
"apikey": gigya_apikey,
"user-agent": gigya_useragent,
"content-type": "application/x-www-form-urlencoded"
Expand Down Expand Up @@ -143,7 +142,7 @@ def gigya_login(email, password):
"ucid": gigya_ucid
}

url = "https://accounts.us1.gigya.com/accounts.getJWT"
url = "https://accounts." + gigya_domain + "/accounts.getJWT"
params["sig"] = gigya_sign(gigya_session_secret, "POST", url, params)

r = do_http("POST", url, headers={
Expand Down

0 comments on commit 3741eaa

Please sign in to comment.