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 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 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 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 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 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
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 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)
class Rogers: """ @class Rogers MSO class to handle authorization with the Rogers MSO """ @staticmethod def getID(): return 'Rogers' @staticmethod 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) @staticmethod 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 Cookies.saveCookieJar(jar) return True
class ShawGo: """ @class ShawGo MSO class to handle authorization with the Shaw MSO """ @staticmethod def getID(): return 'ShawGo' @staticmethod 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) @staticmethod def getAuthn(username, password, saml, relay, 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)) values = {'SAMLRequest': saml, 'RelayState': relay} try: resp = opener.open(url, urllib.urlencode(values)) except urllib2.URLError, e: print e.args 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=\"adobeRequestSaml\".*?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) # ooc is username, email is shawemail, account number is shawdirect idp = 'shawocc' if username.isdigit(): idp = 'shawdirect' elif "@" in username: idp = 'shawemail' # rejig the URL o = urlparse(url) newurl = o.scheme + "://" + o.netloc + action return ShawGo.getEntitlement(username, password, saml, relay, idp, newurl)
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 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) 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)
@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 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) 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)
class Telus: """ @class Telus MSO class to handle authorization with the Shaw MSO. IMPORTANT (if you are ever trying to figure out what goes on here). The telus authentication does a really weird thing (well, its weird to me, but I'm not a webdev -- maybe this isn't weird. If you aren't me and you are reading this, do you think its weird? let me know in the comments -- don't forget to subscribe) where it calls the SOS page, then the bookend page twice. Then, it calls SOS again, and then bookend twice again. Finally, on that fourth call to bookend, we are sent to the logon page. """ @staticmethod def getID(): return 'telus_auth-gateway_net' @staticmethod 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) @staticmethod 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 Cookies.saveCookieJar(jar) html = resp.read() values = parseForm(['AuthState', 'id', 'coeff'], html) if values == None: print "Form parsing failed in getBookend" return None values['history'] = '2' return Telus.getBookendAgain(username, password, values, resp.url.split('?')[0])
class SportsnetNow: def __init__(self): """ Initialize the sportsnet class """ self.CONFIG_URI = 'http://nlmobile.cdnak.neulion.com/sportsnetnow/config/config_ios_r3.xml' self.CHANNELS_URI = 'http://now.sportsnet.ca/service/channels?format=json' self.AUTHORIZED_MSO_URI = 'https://sp.auth.adobe.com/adobe-services/1.0/config/SportsnetNow' self.PUBLISH_POINT = 'https://now.sportsnet.ca/service/publishpoint?' self.USER_AGENT = 'Mozilla/5.0 (iPad; CPU OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F69 ipad sn now 4.0912' self.EPG_PREFIX = 'http://smb.cdnak.nyc.neulion.com/u/smb/sportsnetnow/configs/epg/' @staticmethod def instance(): return SportsnetNow() def name(self): return "Sportsnet Now" def getCategories(self): return ['live'] def getRequestorID(self): return "SportsnetNow" def getSignedRequestorID(self): return 'HR4BsuvUHVRcLrqOpFrm0ZI6oXXWEMH0HJc9NeoXSDFn80xaMuZP9TR5uBVX4C3NrrbNmHRElI0vSYr9OMMCh+ttUvYsU5zBfpCnJYyND5ivjYT6x7eBRKo1+dUQvLSqzCP5VtR4AtbWEgJYnZmokDhLdwn43TpY9QJWW5SDYfPDagG3X5GIVX1THiJOGdbQ2J3T/+3hppkvkZ0dncO6k7kQRhjBJl82huECAJo2QhxqP3OrpfHC2fi3TdPioCig+kS/USGje4kHK2Lu0eb/RsT3HpmTlybrMlU43Yd9tBg4r3yr9Apwra07g6hv/Cd3iHkUkUE6AAJi1GsGpGE6BVb1qNtQYfWIq2AGS9cyh6eVkJeUjWIaleSQKkpzITT89osu2gfgeW5qtywJvfS8wf1IRQT5vqx4jXS1MQwlaznVY4qpWmtH0RCZfww/jIYMwLLI4L4CtwtH8V8jIesYkrwICn/YxC4QSeRLhFMMWyWPmc0E0KXYspv19wX/XJFlhTTSPKtVRAN1kxuq26W9PNPsGonq3ebuFNb4Jgld4k4VTlTLOGg7CEEj09TTTnAx2Der5jegn3B+uPs5/cb64+LWbR9z7GxDRSGvR7rSCczrurNgTVfDopYiRZr8vbHDIaTMXyupuEmt4IH8TxXfowu9vsAlfEdNv1PIdI2uHco=' def getDeviceID(self): #return 64 hex characters settings = Settings.instance().get(self.getRequestorID()) dev_id = '' if not settings: dev_id = '' elif 'DEV_ID' in settings.keys(): dev_id = settings['DEV_ID'] if not dev_id: print "id is empty joining crap" dev_id = ''.join( random.choice('0123456789abcdef') for _ in range(64)) Settings.instance().store(self.getRequestorID(), 'DEV_ID', dev_id) return dev_id def getAuthURI(self, mso): """ Get the Sportsnet Now OAuth URI. This is going to be called by the MSO class to get the authorization URI for hte specific provider @param mso the multi-system operator (eg: Rogers) """ return 'https://sp.auth.adobe.com/adobe-services/1.0/authenticate/saml?domain_name=adobe.com&noflash=true&mso_id=' + mso + '&requestor_id=SportsnetNow&no_iframe=true&client_type=iOS&client_version=1.8&redirect_url=http://adobepass.ios.app/' 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 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 Cookies.saveCookieJar(jar) config_xml = resp.read() dom = xml.dom.minidom.parseString(config_xml) result_node = dom.getElementsByTagName('result')[0] map_node = result_node.getElementsByTagName('channelResourceMap')[0] for chan_node in map_node.getElementsByTagName('channel'): cid = chan_node.attributes['id'] abr = chan_node.attributes['resourceId'] chan_map[cid.value] = abr.value Settings.instance().store(self.getRequestorID(), 'CHAN_MAP', chan_map) return chan_map