def callback(self, *args, **kwargs): """ A callback handler for Google OAuth. It collects the state and code from the callback and posts them to the CloudCV API endpoint for Google callback. The response is stored in a local config file to avoid Auth process in future. """ state = kwargs['state'] code = kwargs['code'] result = requests.post(conf.BASE_URL + '/callback/google/', data={ 'code': code, 'state': state }) print result.text try: account_info = json.loads(result.text) except Exception: return result.text accounts.account_obj = accounts.Accounts() accounts.account_obj.gaccount = accounts.GoogleAccounts(str(account_info['id']), str(account_info['email'])) accounts.writeAccounts(accounts.account_obj) accounts.googleAuthentication=True http_response = "You have been authenticated to CloudCV using your google account." return http_response
def dropbox_callback(self, *args, **kwargs): """ A callback handler for Dropbox authentication. It requires a user to be authenticated with A Google account first. The `code` and `state` parameters in the callback are posted to CloudCV API endpoint. """ state = kwargs['state'] code = kwargs['code'] result = requests.post(conf.BASE_URL + '/callback/dropbox/', data={ 'code': code, 'state': state, 'userid': accounts.account_obj.getGoogleUserID() }) try: account_info = json.loads(result.text) except Exception: return result.text accounts.account_obj.dbaccount = accounts.DropboxAccounts(str(account_info['uid']), str(account_info['token'])) print "Dropbox Account:", str(account_info['uid']) print "Dropbox Token:", str(account_info['token']) redis_obj.set('dropbox_token', account_info['token']) redis_obj.set('dropbox_account', account_info['uid']) accounts.writeAccounts(accounts.account_obj) accounts.dropboxAuthentication = True http_response = "Your dropbox account is now linked" return http_response
def callback(self, *args, **kwargs): state = kwargs['state'] code = kwargs['code'] result = requests.post('http://cloudcv.org/cloudcv/callback/google/', data={ 'code': code, 'state': state }) print result.text try: account_info = json.loads(result.text) except Exception: return result.text accounts.account_obj = accounts.Accounts() accounts.account_obj.gaccount = accounts.GoogleAccounts(str(account_info['id']), str(account_info['email'])) accounts.writeAccounts(accounts.account_obj) accounts.googleAuthentication=True http_response = "You have been authenticated to CloudCV using your google account" return http_response
def dropbox_callback(self, *args, **kwargs): state = kwargs['state'] code = kwargs['code'] result = requests.post('http://cloudcv.org/cloudcv/callback/dropbox/', data={ 'code': code, 'state': state, 'userid': accounts.account_obj.getGoogleUserID() }) try: account_info = json.loads(result.text) except Exception: return result.text accounts.account_obj.dbaccount = accounts.DropboxAccounts(str(account_info['uid']), str(account_info['token'])) accounts.writeAccounts(accounts.account_obj) accounts.dropboxAuthentication = True http_response = "Your dropbox account is now linked" return http_response