def authorize(streamProvider, username, password): """ Perform authorization with Telus @param streamProvider the stream provider object. Needs to handle the getAuthURI. @param username the username to authenticate with @param password the password to authenticate with """ uri = streamProvider.getAuthURI('telus_auth-gateway_net') jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open(uri) except: print "Unable get Telus OAUTH location" return None Cookies.saveCookieJar(jar) html = resp.read() values = parseForm(['SAMLRequest', 'RelayState'], html) action = values.pop('action') if values == None: print "Form parsing failed in authorize" return None return Telus.getBookend(username, password, values, action)
def authorize(streamProvider, username, password): """ Perform authorization with Rogers @param streamProvider the stream provider object. Needs to handle the getAuthURI. @param username the username to authenticate with @param password the password to authenticate with """ uri = streamProvider.getAuthURI('Rogers') jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))#, #urllib2.HTTPHandler(debuglevel=1), #urllib2.HTTPSHandler(debuglevel=1)) try: resp = opener.open(uri) except: print "Unable get OAUTH location" return None Cookies.saveCookieJar(jar) html = resp.read() viewstate = re.search('<input.*__VIEWSTATE.*?value=\"(.*?)\".*?>', html, re.MULTILINE) if not viewstate: return None validation = re.search('<input.*__EVENTVALIDATION.*?value=\"(.*?)\".*?>', html, re.MULTILINE) if not validation: return None return Rogers.getOAuthToken(username, password, viewstate.group(1), validation.group(1), resp.url)
def __init__(self, authentication=None, configuration=None): super(SciServerClient, self).__init__(configuration=configuration) self.user_agent = 'SciServer Footprint Service Client/1.0.0/python' self.authentication = authentication self.cookies = Cookies()
class SciServerClient(ApiClient): """SciServer wrapper around auto-generated API client Supports SciServer token authentication and session cookies """ def __init__(self, authentication=None, configuration=None): super(SciServerClient, self).__init__(configuration=configuration) self.user_agent = 'SciServer Footprint Service Client/1.0.0/python' self.authentication = authentication self.cookies = Cookies() def request(self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, _request_timeout=None): if self.authentication is not None: if headers is None: headers = {} headers['X-Auth-Token'] = authentication.getToken() if self.cookies is not None and len(self.cookies) > 0: headers['Cookie'] = self.cookies.render_request() response = super(SciServerClient, self).request(method, url, query_params, headers, post_params, body, _preload_content, _request_timeout) set_cookies = [] if _preload_content: cc = response.urllib3_response.headers._container else: cc = response.headers._container if 'set-cookie' in cc: c = cc['set-cookie'] for i in range(1, len(c)): set_cookies.append(c[i]) if set_cookies: for c in set_cookies: cc = Cookies.from_response(c) for key in cc: self.cookies.add(cc[key]) return response
def check_cookie(handler, userId=None): cookies = Cookies(handler) if cookies.__contains__('sessionid') and memcache.get(cookies['sessionid']): sessionId=cookies['sessionid'] userId=str(base64.b64decode(memcache.get(sessionId))).strip() memcache.set(sessionId, memcache.get(sessionId)) return userId elif userId: uniqueId=str(uuid.uuid1()) cookies['sessionid'] = uniqueId memcache.add(uniqueId, str(base64.b64encode(userId))) return userId return None
def authorize(streamProvider, username, password): """ Perform authorization with Cogeco @param streamProvider the stream provider object. @param username the username to authenticate with @param password the password to authenticate with """ uri = streamProvider.getAuthURI("Cogeco") jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) #, #urllib2.HTTPHandler(debuglevel=1), #urllib2.HTTPSHandler(debuglevel=1)) # TODO: move this into a method that can be reused.. multiple calls.. try: resp = opener.open(uri) except: print "Unable to redirect to auth page." return None Cookies.saveCookieJar(jar) html = resp.read() # TODO: this could be made a function to to parse and return the value based on an expression action = re.search('<form.*?action=\"(.*?)"', html, re.MULTILINE) if not action: print "Unable to find action form" return None action = action.group(1) saml = re.search('<input.*?name=\"SAMLRequest\".*?value=\"(.*?)\"', html, re.MULTILINE) if not saml: print "Unable to find SAML requst." return None saml = saml.group(1) relay = re.search('<input.*?name=\"RelayState\".*?value=\"(.*?)\"', html, re.MULTILINE) if not relay: print "Unable to find relay state." return None relay = relay.group(1) return Cogeco.postAuthSaml(username, password, saml, relay, action)
def __init__(self, args): super(HttpScan, self).__init__(args) self.session = requesocks.session() adapters.DEFAULT_RETRIES = self.args.max_retries self.tor = None if self.args.tor: self.out.log("Enabling TOR") self.tor = Torify() self.session.proxies = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'} if self.args.check_tor: # Check TOR self.out.log("Checking IP via TOR") rip, tip = self.tor.check_ip(verbose=True) if tip is None: self.out.log('TOR is not working properly!', logging.ERROR) exit(-1) if self.args.cookies is not None: if path.exists(self.args.cookies) and path.isfile(self.args.cookies): self.cookies = MozillaCookieJar(self.args.cookies) self.cookies.load() else: # self.out.log('Could not find cookie file: %s' % self.args.load_cookies, logging.ERROR) self.cookies = Cookies.from_request(self.args.cookies) else: self.cookies = None self.ua = UserAgent() if self.args.user_agent is None else self.args.user_agent
def authorizeDevice(self, streamProvider, mso_id, channel): """ Authorise the device for a particular channel. @param streamProvider the stream provider (eg: the SportsnetNow instance) @param mso_id the MSO identifier (eg: 'Rogers') @param channel the channel identifier """ settings = Settings.instance().get('adobe') values = { 'resource_id': channel, 'requestor_id': streamProvider.getRequestorID(), 'signed_requestor_id': streamProvider.getSignedRequestorID(), 'mso_id': mso_id, 'authentication_token': settings['AUTHN_TOKEN'], 'device_id': streamProvider.getDeviceID(), 'userMeta': '1' } jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.AUTHORIZE_URI, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return False
def preAuthorize(self, streamProvider, resource_ids): """ Pre-authroize. This _should_ get a list of authorised channels. @param streamProvider the stream provider (eg: the SportsnetNow instance) @param resource_ids a list of resources to preauthorise @return a dictionary with each resource id as a key and boolean value indicating if the resource could be authorised """ settings = Settings.instance().get('adobe') values = { 'authentication_token': settings['AUTHN_TOKEN'], 'requestor_id': streamProvider.getRequestorID() } value_str = urllib.urlencode(values) for k in resource_ids.keys(): value_str += '&' + urllib.urlencode( {'resource_id': resource_ids[k]}) jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.PREAUTHORIZE_URI, value_str) except urllib2.URLError, e: print e.args return None
def deviceShortAuthorize(self, streamProvider, mso_id): """ Authorise for a particular channel... a second time. @param streamProvider the stream provider (eg: the SportsnetNow instance) @param mso_id the MSO identifier (eg: 'Rogers') @return the session token required to authorise video the stream """ settings = Settings.instance().get('adobe') values = { 'requestor_id' : streamProvider.getRequestorID(), 'signed_requestor_id' : streamProvider.getSignedRequestorID(), 'session_guid' : uuid.uuid4(), 'hashed_guid' : 'false', 'authz_token' : settings['AUTHZ_TOKEN'], 'mso_id' : mso_id, 'device_id' : streamProvider.getDeviceID() } jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.DEVICE_SHORT_AUTHORIZE, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return ''
def _cookies_from_headers(headers): # Temporarily remove the comma from expires date strings date_safe = re.sub(r'expires=(...),', r'expires=\1#', headers['set-cookie'], flags=re.IGNORECASE) # Split cookies by newline instead of commas line_split = "\n".join([c.strip() for c in date_safe.split(",")]) # Restore date commas cookie_string = re.sub(r'expires=(...)#', r'expires=\1,', line_split, flags=re.IGNORECASE) try: import http.cookies as cookies resp_cookie = cookies.SimpleCookie() resp_cookie.load(cookie_string) cookies_dict = {name: v.value for name, v in resp_cookie.items()} except ImportError: from cookies import Cookies resp_cookies = Cookies.from_response(cookie_string) cookies_dict = {v.name: v.value for _, v in resp_cookies.items()} return cookiejar_from_dict(cookies_dict)
def getEntitlement(username, password, saml, relay, idp, url): """ Get entitlement @param username the username @param password the password @param saml the SAML request (form data) @param relay the relay state (form data) @param idp the logon type (form data) @param url the entitlement URL """ jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = { 'adobeRequestSaml': saml, 'relayState': relay, 'username': username, 'password': password, 'IdpAdapterid': idp } try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args
def preAuthorize(self, streamProvider, resource_ids): """ Pre-authroize. This _should_ get a list of authorised channels. @param streamProvider the stream provider (eg: the SportsnetNow instance) @param resource_ids a list of resources to preauthorise @return a dictionary with each resource id as a key and boolean value indicating if the resource could be authorised """ settings = Settings.instance().get('adobe') values = { 'authentication_token' : settings['AUTHN_TOKEN'], 'requestor_id' : streamProvider.getRequestorID() } value_str = urllib.urlencode(values) for resource_id in resource_ids: value_str += '&' + urllib.urlencode({ 'resource_id' : resource_id }) jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.PREAUTHORIZE_URI, value_str) except urllib2.URLError, e: print e.args return False
def authorizeDevice(self, streamProvider, mso_id, channel): """ Authorise the device for a particular channel. @param streamProvider the stream provider (eg: the SportsnetNow instance) @param mso_id the MSO identifier (eg: 'Rogers') @param channel the channel identifier """ settings = Settings.instance().get('adobe') values = { 'resource_id' : channel, 'requestor_id' : streamProvider.getRequestorID(), 'signed_requestor_id' : streamProvider.getSignedRequestorID(), 'mso_id' : mso_id, 'authentication_token' : settings['AUTHN_TOKEN'], 'device_id' : streamProvider.getDeviceID(), 'userMeta' : '1' } jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.AUTHORIZE_URI, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return False
def callback(username, password): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(Sportsnet.USER_AGENT))] values = { 'callback' : 'mvpdSignInCallback', 'username' : username, 'password' : password, 't' : str(int(time.time())) } try: resp = opener.open('https://now.sportsnet.ca/secure/mvpd/myrogers?'+urllib.urlencode(values)) except: print "Unable to login with signinmvpd" return False res = resp.read() json_data = re.search('mvpdSignInCallback\((.*?)\)', res, re.MULTILINE) if not json_data: return False jsres = json.loads(json_data.group(1)) if not 'code' in jsres.keys(): return True if jsres['code'] != 'loginsuccess': return False return True
def login_messenger(self, driver): msg_driver = Cookies(driver) try: msg_driver.get_cookies() driver.refresh() time.sleep(4) except EOFError: username = driver.find_element_by_id("email") password = driver.find_element_by_id("pass") username.send_keys(self.email) password.send_keys(self.passwd) driver.find_element_by_name("login").click() time.sleep(4) msg_driver.log_cookies()
def _on_request(self, adapter, request, **kwargs): match = self._find_match(request) # TODO(dcramer): find the correct class for this if match is None: error_msg = 'Connection refused: {0} {1}'.format(request.method, request.url) response = ConnectionError(error_msg) response.request = request self._calls.add(request, response) raise response if 'body' in match and isinstance(match['body'], Exception): self._calls.add(request, match['body']) raise match['body'] headers = {} if match['content_type'] is not None: headers['Content-Type'] = match['content_type'] if 'callback' in match: # use callback status, r_headers, body = match['callback'](request) if isinstance(body, six.text_type): body = body.encode('utf-8') body = BufferIO(body) headers.update(r_headers) elif 'body' in match: if match['adding_headers']: headers.update(match['adding_headers']) status = match['status'] body = BufferIO(match['body']) response = HTTPResponse( status=status, reason=six.moves.http_client.responses[status], body=body, headers=headers, preload_content=False, # Need to not decode_content to mimic requests decode_content=False, ) response = adapter.build_response(request, response) if not match.get('stream'): response.content # NOQA try: resp_cookies = Cookies.from_request(response.headers['set-cookie']) response.cookies = cookiejar_from_dict(dict( (v.name, v.value) for _, v in resp_cookies.items() )) except (KeyError, TypeError): pass self._calls.add(request, response) return response
def deviceShortAuthorize(self, streamProvider, mso_id): """ Authorise for a particular channel... a second time. @param streamProvider the stream provider (eg: the SportsnetNow instance) @param mso_id the MSO identifier (eg: 'Rogers') @return the session token required to authorise video the stream """ settings = Settings.instance().get('adobe') values = { 'requestor_id': streamProvider.getRequestorID(), 'signed_requestor_id': streamProvider.getSignedRequestorID(), 'session_guid': uuid.uuid4(), 'hashed_guid': 'false', 'authz_token': settings['AUTHZ_TOKEN'], 'mso_id': mso_id, 'device_id': streamProvider.getDeviceID() } jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.DEVICE_SHORT_AUTHORIZE, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return ''
def authorize(streamProvider, username, password): """ Perform authorization with ShawGo @param streamProvider the stream provider object. Needs to handle the getAuthURI. @param username the username to authenticate with @param password the password to authenticate with """ uri = streamProvider.getAuthURI('ShawGo') jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) #, #urllib2.HTTPHandler(debuglevel=1), #urllib2.HTTPSHandler(debuglevel=1)) try: resp = opener.open(uri) except: print "Unable get OAUTH location" return None Cookies.saveCookieJar(jar) html = resp.read() action = re.search('<form.*?action=\"(.*?)"', html, re.MULTILINE) if not action: print "Unable to find action form" return None action = action.group(1) saml = re.search('<input.*?name=\"SAMLRequest\".*?value=\"(.*?)\"', html, re.MULTILINE) if not saml: print "Unable to find SAML requst." return None saml = saml.group(1) relay = re.search('<input.*?name=\"RelayState\".*?value=\"(.*?)\"', html, re.MULTILINE) if not relay: print "Unable to find relay state." return None relay = relay.group(1) return ShawGo.getAuthn(username, password, saml, relay, action)
def completeBackgroundLogin(): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open('https://sp.auth.adobe.com/adobe-services/completeBackgroundLogin') except urllib2.URLError, e: print e.args
def __init__(self, search_engines): super(Complementary, self).__init__(name="complementary") self.scripting = Scripting(search_engines, parent=self) self.cookies = Cookies(parent=self) self.dice = Dice(parent=self) self.m*******t = M*******t(parent=self) self.online = Online(parent=self) self.log.info("load complete")
def __init__(self, para_id): self.url_queue = None self.Crawler = None self.db = None self.para_id = para_id self.coro_num = 3 self.keyword_list = None self.cookies = Cookies().get_cookies()
def authorize(streamProvider, username, password): """ Perform authorization with Cogeco @param streamProvider the stream provider object. @param username the username to authenticate with @param password the password to authenticate with """ uri = streamProvider.getAuthURI("Cogeco") jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))#, #urllib2.HTTPHandler(debuglevel=1), #urllib2.HTTPSHandler(debuglevel=1)) # TODO: move this into a method that can be reused.. multiple calls.. try: resp = opener.open(uri) except: print "Unable to redirect to auth page." return None Cookies.saveCookieJar(jar) html = resp.read() # TODO: this could be made a function to to parse and return the value based on an expression action = re.search('<form.*?action=\"(.*?)"', html, re.MULTILINE) if not action: print "Unable to find action form" return None action = action.group(1) saml = re.search('<input.*?name=\"SAMLRequest\".*?value=\"(.*?)\"', html, re.MULTILINE) if not saml: print "Unable to find SAML requst." return None saml = saml.group(1) relay = re.search('<input.*?name=\"RelayState\".*?value=\"(.*?)\"', html, re.MULTILINE) if not relay: print "Unable to find relay state." return None relay = relay.group(1) return Cogeco.postAuthSaml(username, password, saml, relay, action)
def _on_request(self, adapter, request, **kwargs): match = self._find_match(request) # TODO(dcramer): find the correct class for this if match is None: error_msg = 'Connection refused: {0} {1}'.format(request.method, request.url) response = ConnectionError(error_msg) response.request = request self._calls.add(request, response) raise response if 'body' in match and isinstance(match['body'], Exception): self._calls.add(request, match['body']) raise match['body'] headers = {} if match['content_type'] is not None: headers['Content-Type'] = match['content_type'] if 'callback' in match: # use callback status, r_headers, body = match['callback'](request) if isinstance(body, six.text_type): body = body.encode('utf-8') body = BufferIO(body) headers.update(r_headers) elif 'body' in match: if match['adding_headers']: headers.update(match['adding_headers']) status = match['status'] body = BufferIO(match['body']) response = HTTPResponse( status=status, reason=six.moves.http_client.responses[status], body=body, headers=headers, preload_content=False, ) response = adapter.build_response(request, response) if not match.get('stream'): response.content # NOQA try: resp_cookies = Cookies.from_request(response.headers['set-cookie']) response.cookies = cookiejar_from_dict(dict( (v.name, v.value) for _, v in resp_cookies.items() )) except (KeyError, TypeError): pass self._calls.add(request, response) return response
def run(self): # 提取redis数据库中的账号,进行对比,看哪个账号换没有获取cookies account_usernames = self.account_db.usernames() cookies_usernames = self.cookies_db.usernames() for username in account_usernames: # 如果账号没有存在与cookies表中说明没有获取cookies if not username in cookies_usernames: password = self.account_db.get(username) print('正在生成账号为%s的cookies' % username) # 这块是我们cookies文件中的返回结果 result = Cookies(username, password).main() time.sleep(10) if result.get('status') == 1: # cookies = self.process_cookies(result.get('content')) cookies = result.get('content') print('成功获取到cookies', cookies) if self.cookies_db.set(username, json.dumps(cookies)): print("成功保存cookies") elif result.get('status') == 2: print(result.get('content')) if self.account_db.delete(username): print('成功删除错误账号') else: print(result.get('content'))
def authorize(streamProvider, username, password): """ Perform authorization with ShawGo @param streamProvider the stream provider object. Needs to handle the getAuthURI. @param username the username to authenticate with @param password the password to authenticate with """ uri = streamProvider.getAuthURI('ShawGo') jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))#, #urllib2.HTTPHandler(debuglevel=1), #urllib2.HTTPSHandler(debuglevel=1)) try: resp = opener.open(uri) except: print "Unable get OAUTH location" return None Cookies.saveCookieJar(jar) html = resp.read() action = re.search('<form.*?action=\"(.*?)"', html, re.MULTILINE) if not action: print "Unable to find action form" return None action = action.group(1) saml = re.search('<input.*?name=\"SAMLRequest\".*?value=\"(.*?)\"', html, re.MULTILINE) if not saml: print "Unable to find SAML requst." return None saml = saml.group(1) relay = re.search('<input.*?name=\"RelayState\".*?value=\"(.*?)\"', html, re.MULTILINE) if not relay: print "Unable to find relay state." return None relay = relay.group(1) return ShawGo.getAuthn(username, password, saml, relay, action)
def checkMSOs(self): """ Check the available MSOs. We don't actually use anything from this request other than the cookies returned. """ jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.AUTHORIZED_MSO_URI) except: print "Unable get OAUTH location" return None Cookies.saveCookieJar(jar) mso_xml = resp.read() return None
def checkMSOs(self): """ Check the available MSOs. We don't actually use anything from this request other than the cookies returned. """ jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [("User-Agent", urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.AUTHORIZED_MSO_URI) except: print "Unable get OAUTH location" return None Cookies.saveCookieJar(jar) mso_xml = resp.read() return None
def getChannels(self): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [("User-Agent", urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.CHANNELS_URI) except urllib2.URLError, e: print e.args return None
def completeBackgroundLogin(): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open( 'https://sp.auth.adobe.com/adobe-services/completeBackgroundLogin' ) except urllib2.URLError, e: print e.args
def authGateway(values, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: if e.reason[1] == "No address associated with hostname": return True return None
def getSAMLAssertionConsumer(saml, relay, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = {'SAMLResponse': saml, 'RelayState': relay} try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args
def getChannels(self): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.CHANNELS_URI) except urllib2.URLError, e: print e.args return None
def postLogin(username, password, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = {'username': username, 'password': password} try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args
def discoveryAssociations(url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = {'AuthState': url[url.find('='):]} try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return None
def discoveryAssociations(url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = { 'AuthState' : url[url.find('='):] } try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return None
def _cookies_from_headers(headers): if sys.version_info[:2] < (3, 4): from cookies import Cookies resp_cookies = Cookies.from_request(headers["set-cookie"]) cookies_dict = {v.name: v.value for _, v in resp_cookies.items()} else: import biscuits cookies_dict = biscuits.parse(headers["set-cookie"]) return cookiejar_from_dict(cookies_dict)
def getBookendAgain(username, password, values, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = urllib.urlencode(values) url += '?' + values try: resp = opener.open(url, values) except urllib2.URLError, e: print e.args return None
class AdobePass: def __init__(self): """ Initialise the adobe pass. """ self.SESSION_DEVICE_URI = 'https://sp.auth.adobe.com/adobe-services/1.0/sessionDevice' self.PREAUTHORIZE_URI = 'https://sp.auth.adobe.com/adobe-services/1.0/preauthorize' self.AUTHORIZE_URI = 'https://sp.auth.adobe.com/adobe-services/1.0/authorizeDevice' self.DEVICE_SHORT_AUTHORIZE = 'https://sp.auth.adobe.com/adobe-services/1.0/deviceShortAuthorize' self.USER_AGENT = 'AdobePassNativeClient/1.8 (iPad; U; CPU iPad OS 8.3 like Mac OS X; en-us)' def sessionDevice(self, streamProvider): """ Session Device. """ jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) #, #urllib2.HTTPHandler(debuglevel=1), #urllib2.HTTPSHandler(debuglevel=1)) values = { 'requestor_id': streamProvider.getRequestorID(), 'signed_requestor_id': streamProvider.getSignedRequestorID(), '_method': 'GET', 'device_id': streamProvider.getDeviceID() } opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.SESSION_DEVICE_URI, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return False Cookies.saveCookieJar(jar) resp_xml = resp.read() dom = xml.dom.minidom.parseString(resp_xml) result_node = dom.getElementsByTagName('result')[0] tok_node = result_node.getElementsByTagName('authnToken')[0] meta_node = result_node.getElementsByTagName('userMeta')[0] token = tok_node.firstChild.nodeValue meta = meta_node.firstChild.nodeValue s = Settings.instance() s.store('adobe', 'AUTHN_TOKEN', token) s.store('adobe', 'USER_META', meta) return True
def postAuthSaml(username, password, saml, relay, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = {'SAMLRequest': saml, 'RelayState': relay} try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return None
def getSAMLAssertionConsumer(saml, relay, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = {'SAMLResponse' : saml, 'RelayState' : relay } try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args
def postLogin(username, password, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = { 'username' : username, 'password' : password } try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args
def authorize(streamProvider, username, password): """ Perform authorization with Rogers @param streamProvider the stream provider object. Needs to handle the getAuthURI. @param username the username to authenticate with @param password the password to authenticate with """ uri = streamProvider.getAuthURI('Rogers') jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) #, #urllib2.HTTPHandler(debuglevel=1), #urllib2.HTTPSHandler(debuglevel=1)) try: resp = opener.open(uri) except: print "Unable get OAUTH location" return None Cookies.saveCookieJar(jar) html = resp.read() viewstate = re.search('<input.*__VIEWSTATE.*?value=\"(.*?)\".*?>', html, re.MULTILINE) if not viewstate: return None validation = re.search( '<input.*__EVENTVALIDATION.*?value=\"(.*?)\".*?>', html, re.MULTILINE) if not validation: return None return Rogers.getOAuthToken(username, password, viewstate.group(1), validation.group(1), resp.url)
def _cookies_from_headers(headers): try: import http.cookies as cookies resp_cookie = cookies.SimpleCookie() resp_cookie.load(headers["set-cookie"]) cookies_dict = {name: v.value for name, v in resp_cookie.items()} except ImportError: from cookies import Cookies resp_cookies = Cookies.from_request(headers["set-cookie"]) cookies_dict = {v.name: v.value for _, v in resp_cookies.items()} return cookiejar_from_dict(cookies_dict)
def obtain_session(self, env): cookie_str = env.get('HTTP_COOKIE', None) session = None if cookie_str: cookie = Cookies.from_request( cookie_str, ignore_bad_cookies=True, ).get('session', None) if cookie and cookie.value: if cookie.value in self.sessions: # Session found session = self.sessions[cookie.value] if session.is_dead(): session = None return session
def lastBookend(values, url): """ Make the lastBookend call """ values['history'] = '7' url = url + '?' + urllib.urlencode(values) jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open(url) except urllib2.URLError, e: print e.args return None
def postAuthSaml(username, password, saml, relay, url): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = { 'SAMLRequest' : saml, 'RelayState' : relay } try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return None
def getGuideData(self): """ Get the guid data for the channels right now. """ now = self.getServerTime() url = self.EPG_PREFIX + now.strftime("%Y/%m/%d.xml") jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(url) except urllib2.URLError, e: print e.args return None
def signinmvpd(): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(Sportsnet.USER_AGENT))] values = { 'id' : 'myrogers' } try: resp = opener.open('https://now.sportsnet.ca/signinmvpd?', urllib.urlencode(values)) except: print "Unable to login with signinmvpd" return False res = resp.read() return True
def getPublishPoint(self, id, name, token): """ Get the stream address. @param name the channel name @param token the token to authorize the stream """ values = {"id": id, "type": "channel", "nt": "1", "aprid": name, "aptoken": token} jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [("User-Agent", urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.PUBLISH_POINT, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return ""
def getBookend(username, password, values, url): """ Perform OAuth @param username the username @param password the password @param saml the SAML request (form data) @param relay the relay state (form data) @param url the entitlement URL """ jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return None
def __init__(self, cnxn, method, url, headers, body): self.cnxn = cnxn self.method = method self.url = url self.headers = headers self.body = body # A counter to help troubleshoot. self._id = Request._next_id Request._next_id = (Request._next_id + 1) % 1000000 self.form = self.parse_form() c = headers.get('cookie', None) if c: self.cookies = Cookies.from_request(c) else: self.cookies = Cookies()
def getChannelResourceMap(self): """ Get the mapping from ID to channel abbreviation """ settings = Settings.instance().get(self.getRequestorID()) chan_map = {} if settings and 'CHAN_MAP' in settings.keys(): return settings['CHAN_MAP'] jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))] try: resp = opener.open(self.CONFIG_URI) except urllib2.URLError, e: print e.args return None