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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
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 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 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 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 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 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 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 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 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 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 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 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
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 login(username, password, html): values = parseForm(['login_type', 'remember_me', 'source', 'source_button'], html) if values == None: print "Form parsing failed in login" return None action = values.pop('action', None) values['username'] = username values['password'] = password jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open(action, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return None
def login(username, password, html): values = parseForm( ['login_type', 'remember_me', 'source', 'source_button'], html) if values == None: print "Form parsing failed in login" return None action = values.pop('action', None) values['username'] = username values['password'] = password jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) try: resp = opener.open(action, urllib.urlencode(values)) except urllib2.URLError, e: print e.args return None
def mvpd(): jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) opener.addheaders = [('User-Agent', urllib.quote(Sportsnet.USER_AGENT))] values = { 'id' : 'myrogers', 'format' : 'json', 'callback' : 'listenRogersSigninCallback', 't' : str(int(time.time())) } try: resp = opener.open('https://now.sportsnet.ca/mvpd?', urllib.urlencode(values)) except: print "Unable to login with mvpd" return False res = resp.read() return True
def getPublishPoint(self, id, name, token): """ Get the stream address. Do not call directly. @param name the channel name @param token the token to authorize the stream """ values = {'format': 'json', 'id': id, 'type': 'channel', 'nt': '1'} if token: values['aprid'] = name values['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 getOAuthToken(username, password, viewstate, validation, url): """ Perform OAuth @param username the username @param password the password @param viewstate the viewstate (form data) @param validation the validation (form data) @param url the OAuth URL """ jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = {'__VIEWSTATE' : viewstate, '__EVENTVALIDATION' : validation, 'UserName' : username, 'UserPassword' : password, 'Login' : 'Sign+in' } 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 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
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 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
def getOAuthToken(username, password, viewstate, validation, url): """ Perform OAuth @param username the username @param password the password @param viewstate the viewstate (form data) @param validation the validation (form data) @param url the OAuth URL """ jar = Cookies.getCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar)) values = { '__VIEWSTATE': viewstate, '__EVENTVALIDATION': validation, 'UserName': username, 'UserPassword': password, 'Login': '******' } try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args
def getPublishPoint(self, id, name, token): """ Get the stream address. Do not call directly. @param name the channel name @param token the token to authorize the stream """ values = { 'format' : 'json', 'id' : id, 'type' : 'channel', 'nt' : '1'} if token: values['aprid'] = name values['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 ''