예제 #1
0
class MusicManagerClient(object):
    """Class to emulate MusicManager Client"""
    ISSUE_AUTH_URL = 'https://www.google.com/accounts/IssueAuthToken'
    ISSUE_AUTH_SERVICE_NAME = 'gaia'
    TOKEN_AUTH_URL = 'https://www.google.com/accounts/TokenAuth'

    def __init__(self, cookies):
        self.cookies = cookies
        self.base_request = MusicManagerRequest(self.cookies)

    def get_issue_auth(self, auth_data, headers):
        """Return an issue auth token"""
        body = {
          'SID': auth_data['SID'], 'LSID': auth_data['LSID'],
          'service': self.ISSUE_AUTH_SERVICE_NAME
        }
        issue_response = self.base_request.request(self.ISSUE_AUTH_URL, 
                                                            body, headers)
        return issue_response.rstrip()

    def authenticate(self, auth_data, service, redirect, source=None):
        """Authenticate against the provided service"""
        headers = {'Content-Type': FORM_CONTENT_TYPE}
        issue_auth = self.get_issue_auth(auth_data, headers)
        params_data = {
          'auth': issue_auth, 'service': service, 'continue': redirect
        }
        if source:
            params_data['source'] = source

        params = urllib.urlencode(params_data)
        url = '%s?%s' % (self.TOKEN_AUTH_URL, params)
        # Get session cookies
        return self.base_request.request(url, None, headers)
예제 #2
0
 def __init__(self, cookies):
     self.cookies = cookies
     self.base_request = MusicManagerRequest(self.cookies)