def authenticate(self, client_id_fp, key_fp, testmode=False): if not os.path.isfile(client_id_fp) or not os.path.isfile(key_fp): print("! Err: did not find {0} or {1}".format( client_id_fp, key_fp)) return False with open(client_id_fp) as f: client_id = f.read().strip() with open(key_fp) as f: key = f.read().strip() if testmode: nonce = self._get_testmode_auth_nonce(client_id) else: nonce = self._get_auth_nonce(client_id) if not nonce: self.err_print("cannot get nonce") return False sig_maker = httpsig.Signer(secret=key, algorithm='rsa-sha256') try: signed_nonce = sig_maker._sign(nonce) except AttributeError: signed_nonce = sig_maker.sign(nonce) except BaseException as e: print("err:" + str(e)) return False return self._put_auth({ "client_id": client_id, "nonce_signed": signed_nonce })
def authenticate(self, client_id, key): sig_maker = httpsig.Signer(secret=key, algorithm='rsa-sha256') nonce = self._get_nonce(client_id) signed_nonce = sig_maker._sign(nonce) url = "{base_url}/auth".format(base_url=self.base_url) data = {"client_id": client_id, "nonce_signed": signed_nonce} r = requests.put(url, json=data, verify=False) _, credentials = r.headers["Set-Cookie"].split("; ")[0].split("=") self.cookies["Credentials"] = credentials
def authenticate(self, path_to_private_key='privs/key.pem'): secret = open(path_to_private_key, 'rb').read() sig_maker = httpsig.Signer(secret=secret, algorithm='rsa-sha256') nonce = self.get_nonce() signed_nonce = sig_maker._sign(nonce) url = f"{self.base_url}/auth" data = {"client_id": self.client_id, "nonce_signed": signed_nonce} r = requests.put(url, json=data, verify=False) _, credentials = r.headers["Set-Cookie"].split("; ")[0].split("=") self.cookies["Credentials"] = credentials
def authenticate(self, client_id, key): sig_maker = httpsig.Signer(secret=key, algorithm="rsa-sha256") nonce = self._get_nonce(client_id) signed_nonce = sig_maker.sign(nonce) url = "{base_url}/auth".format(base_url=self.base_url) data = {"client_id": client_id, "nonce_signed": signed_nonce} r = self.session.put(url, json=data) # cookiejar cannot parse the cookie format used by the tablet, # so we have to set it manually. _, credentials = r.headers["Set-Cookie"].split("; ")[0].split("=") self.session.cookies["Credentials"] = credentials return r