Beispiel #1
0
    def getAuthorizationUrl(self):

        referer = getParam('host')
        callback_url = cleanHost(referer) + '%snotify.%s.credentials/' % (url_for('api.index').lstrip('/'), self.getName().lower())

        oauth_consumer = oauth2.Consumer(self.consumer_key, self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer)

        resp, content = oauth_client.request(self.urls['request'], 'POST', body = tryUrlencode({'oauth_callback': callback_url}))

        if resp['status'] != '200':
            log.error('Invalid response from Twitter requesting temp token: %s' % resp['status'])
            return jsonified({
                'success': False,
            })
        else:
            self.request_token = dict(parse_qsl(content))

            auth_url = self.urls['authorize'] + ("?oauth_token=%s" % self.request_token['oauth_token'])

            log.info('Redirecting to "%s"' % auth_url)
            return jsonified({
                'success': True,
                'url': auth_url,
            })
Beispiel #2
0
    def getCredentials(self, key):
        request_token = {
            'oauth_token': self.conf('username'),
            'oauth_token_secret': self.conf('password'),
            'oauth_callback_confirmed': True
        }

        token = oauth2.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
        token.set_verifier(key)

        log.info('Generating and signing request for an access token using key: %s' % key)

        oauth_consumer = oauth2.Consumer(key = self.consumer_key, secret = self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer, token)

        resp, content = oauth_client.request(self.url['access'], method = 'POST', body = 'oauth_verifier=%s' % key)
        access_token = dict(parse_qsl(content))

        if resp['status'] != '200':
            log.error('The request for an access token did not succeed: ' + str(resp['status']))
            return False
        else:
            log.info('Your Twitter access token is %s' % access_token['oauth_token'])
            log.info('Access token secret is %s' % access_token['oauth_token_secret'])

            Env.setting('username', section = 'twitter', value = access_token['oauth_token'])
            Env.setting('password', section = 'twitter', value = access_token['oauth_token_secret'])

            return True
Beispiel #3
0
    def getCredentials(self):

        key = getParam('oauth_verifier')

        token = oauth2.Token(self.request_token['oauth_token'], self.request_token['oauth_token_secret'])
        token.set_verifier(key)

        oauth_consumer = oauth2.Consumer(key = self.consumer_key, secret = self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer, token)

        resp, content = oauth_client.request(self.urls['access'], method = 'POST', body = 'oauth_verifier=%s' % key)
        access_token = dict(parse_qsl(content))

        if resp['status'] != '200':
            log.error('The request for an access token did not succeed: %s' % resp['status'])
            return 'Twitter auth failed'
        else:
            log.debug('Tokens: %s, %s' % (access_token['oauth_token'], access_token['oauth_token_secret']))

            self.conf('access_token_key', value = access_token['oauth_token'])
            self.conf('access_token_secret', value = access_token['oauth_token_secret'])
            self.conf('screen_name', value = access_token['screen_name'])

            self.request_token = None

            return redirect(url_for('web.index') + 'settings/notifications/')
Beispiel #4
0
    def getAuthorizationUrl(self, host=None, **kwargs):

        callback_url = cleanHost(host) + '%snotify.%s.credentials/' % (
            Env.get('api_base').lstrip('/'), self.getName().lower())

        oauth_consumer = oauth2.Consumer(self.consumer_key,
                                         self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer)

        resp, content = oauth_client.request(
            self.urls['request'],
            'POST',
            body=tryUrlencode({'oauth_callback': callback_url}))

        if resp['status'] != '200':
            log.error(
                'Invalid response from Twitter requesting temp token: %s',
                resp['status'])
            return {
                'success': False,
            }
        else:
            self.request_token = dict(parse_qsl(content))

            auth_url = self.urls['authorize'] + (
                "?oauth_token=%s" % self.request_token['oauth_token'])

            log.info('Redirecting to "%s"', auth_url)
            return {
                'success': True,
                'url': auth_url,
            }
Beispiel #5
0
    def getCredentials(self, oauth_verifier, **kwargs):

        token = oauth2.Token(self.request_token['oauth_token'],
                             self.request_token['oauth_token_secret'])
        token.set_verifier(oauth_verifier)

        oauth_consumer = oauth2.Consumer(key=self.consumer_key,
                                         secret=self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer, token)

        resp, content = oauth_client.request(self.urls['access'],
                                             method='POST',
                                             body='oauth_verifier=%s' %
                                             oauth_verifier)
        access_token = dict(parse_qsl(content))

        if resp['status'] != '200':
            log.error('The request for an access token did not succeed: %s',
                      resp['status'])
            return 'Twitter auth failed'
        else:
            log.debug('Tokens: %s, %s', (access_token['oauth_token'],
                                         access_token['oauth_token_secret']))

            self.conf('access_token_key', value=access_token['oauth_token'])
            self.conf('access_token_secret',
                      value=access_token['oauth_token_secret'])
            self.conf('screen_name', value=access_token['screen_name'])

            self.request_token = None

            return 'redirect', Env.get('web_base') + 'settings/notifications/'
Beispiel #6
0
    def getAuthorization(self, referer):

        oauth_consumer = oauth2.Consumer(self.consumer_key,
                                         self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer)

        resp, content = oauth_client.request(
            self.url['request'],
            'POST',
            body=urllib.urlencode({'oauth_callback':
                                   referer + 'twitterAuth/'}))

        if resp['status'] != '200':
            log.error(
                'Invalid response from Twitter requesting temp token: %s' %
                resp['status'])
        else:
            request_token = dict(parse_qsl(content))

            Env.setting('username',
                        section='twitter',
                        value=request_token['oauth_token'])
            Env.setting('password',
                        section='twitter',
                        value=request_token['oauth_token_secret'])

            auth_url = self.url['authorize'] + "?oauth_token=" + request_token[
                'oauth_token']

            log.info('Your Twitter authentication url is "%s"' % auth_url)
            return auth_url
Beispiel #7
0
    def getAuthorization(self, referer):

        oauth_consumer = oauth2.Consumer(self.consumer_key, self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer)

        resp, content = oauth_client.request(self.url['request'], 'POST', body = urllib.urlencode({'oauth_callback': referer + 'twitterAuth/'}))

        if resp['status'] != '200':
            log.error('Invalid response from Twitter requesting temp token: %s' % resp['status'])
        else:
            request_token = dict(parse_qsl(content))

            Env.setting('username', section = 'twitter', value = request_token['oauth_token'])
            Env.setting('password', section = 'twitter', value = request_token['oauth_token_secret'])

            auth_url = self.url['authorize'] + "?oauth_token=" + request_token['oauth_token']

            log.info('Your Twitter authentication url is "%s"' % auth_url)
            return auth_url
Beispiel #8
0
    def getCredentials(self, key):
        request_token = {
            'oauth_token': self.conf('username'),
            'oauth_token_secret': self.conf('password'),
            'oauth_callback_confirmed': True
        }

        token = oauth2.Token(request_token['oauth_token'],
                             request_token['oauth_token_secret'])
        token.set_verifier(key)

        log.info(
            'Generating and signing request for an access token using key: %s'
            % key)

        oauth_consumer = oauth2.Consumer(key=self.consumer_key,
                                         secret=self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer, token)

        resp, content = oauth_client.request(self.url['access'],
                                             method='POST',
                                             body='oauth_verifier=%s' % key)
        access_token = dict(parse_qsl(content))

        if resp['status'] != '200':
            log.error('The request for an access token did not succeed: ' +
                      str(resp['status']))
            return False
        else:
            log.info('Your Twitter access token is %s' %
                     access_token['oauth_token'])
            log.info('Access token secret is %s' %
                     access_token['oauth_token_secret'])

            Env.setting('username',
                        section='twitter',
                        value=access_token['oauth_token'])
            Env.setting('password',
                        section='twitter',
                        value=access_token['oauth_token_secret'])

            return True
Beispiel #9
0
    def getAuthorizationUrl(self, host = None, **kwargs):

        callback_url = cleanHost(host) + '%snotify.%s.credentials/' % (Env.get('api_base').lstrip('/'), self.getName().lower())

        oauth_consumer = oauth2.Consumer(self.consumer_key, self.consumer_secret)
        oauth_client = oauth2.Client(oauth_consumer)

        resp, content = oauth_client.request(self.urls['request'], 'POST', body = tryUrlencode({'oauth_callback': callback_url}))

        if resp['status'] != '200':
            log.error('Invalid response from Twitter requesting temp token: %s', resp['status'])
            return {
                'success': False,
            }
        else:
            self.request_token = dict(parse_qsl(content))

            auth_url = self.urls['authorize'] + ("?oauth_token=%s" % self.request_token['oauth_token'])

            log.info('Redirecting to "%s"', auth_url)
            return {
                'success': True,
                'url': auth_url,
            }