Beispiel #1
0
def auth_verify():
    """
    Get final access token and secret, redirect

    @oauth_verifier = parameter from auth_url callback (see above)
    """
    try:
        oauth_verifier = request.args.get('oauth_verifier')
        if not oauth_verifier:
            raise Exception('expected oauth_verifier parameter')
        auth_token = session_get('auth_token')
        auth_token_secret = session_get('auth_token_secret')
        auth_redirect = session_get('auth_redirect')
        if not (auth_token and auth_token_secret):
            raise Exception('Authorization credentials not found in session')
        tk = get_twitter_keys()
        client = UserClient(tk.consumer_key, tk.consumer_secret,
                    auth_token, auth_token_secret)
        token = client.get_access_token(oauth_verifier)
        session_set('access_token', token.oauth_token)
        session_set('access_token_secret', token.oauth_token_secret)
        session_pop_list(['auth_token', 'auth_token_secret', 'auth_redirect'])
        if auth_redirect:
            return redirect(auth_redirect)
        else:
            return redirect(url_for('home'))
    except Exception, e:
        traceback.print_exc()
        return redirect(auth_redirect)
Beispiel #2
0
def auth_verify():
    """
    Get final access token and secret, redirect

    @oauth_verifier = parameter from auth_url callback (see above)
    """
    try:
        oauth_verifier = request.args.get('oauth_verifier')
        if not oauth_verifier:
            raise Exception('expected oauth_verifier parameter')
        auth_token = session_get('auth_token')
        auth_token_secret = session_get('auth_token_secret')
        auth_redirect = session_get('auth_redirect')
        if not (auth_token and auth_token_secret):
            raise Exception('Authorization credentials not found in session')
        tk = get_twitter_keys()
        client = UserClient(tk.consumer_key, tk.consumer_secret, auth_token,
                            auth_token_secret)
        token = client.get_access_token(oauth_verifier)
        session_set('access_token', token.oauth_token)
        session_set('access_token_secret', token.oauth_token_secret)
        session_pop_list(['auth_token', 'auth_token_secret', 'auth_redirect'])
        if auth_redirect:
            return redirect(auth_redirect)
        else:
            return redirect(url_for('home'))
    except Exception, e:
        traceback.print_exc()
        return redirect(auth_redirect)
Beispiel #3
0
class AuthMaker(object):
    def __init__(self):
        self.client = None
        self.consumer_key = None
        self.consumer_secret = None
        self.access_token = None
        self.access_token_secret = None
        self.token = None
        self.oauth_verifier = None

    def step1(self, key, secret):
        self.consumer_key = key
        self.consumer_secret = secret
        self.client = UserClient(self.consumer_key, self.consumer_secret)

    def step2(self, callback_url):
        self.token = self.client.get_authorize_token(callback_url)
        self.access_token = self.token.oauth_token
        self.access_token_secret = self.token.oauth_token_secret

        print('Please go to: {}'.format(self.token.auth_url))

    def step3(self, oauth_verifier):
        self.oauth_verifier = oauth_verifier
        self.client = UserClient(
            self.consumer_key,
            self.consumer_secret,
            self.access_token,
            self.access_token_secret,
        )
        self.token = self.client.get_access_token(oauth_verifier)

        print('---- ok ----')
        print('ACCESS_TOKEN = {}'.format(self.token.oauth_token))
        print('ACCESS_TOKEN_SECRET = {}'.format(self.token.oauth_token_secret))
Beispiel #4
0
def _upload_to_twitter(image: BytesIO) -> None:
    """Upload an icon to Twitter.

    :param image: the image to upload
    """
    client = UserClient(CONSUMER_KEY, CONSUMER_SECRET)
    verifier = client.get_authorize_token('oob')  # get auth URL
    open(verifier.auth_url)  # open auth URL so user can get PIN

    pin = input('PIN: ')  # get PIN from user

    client = UserClient(CONSUMER_KEY, CONSUMER_SECRET,
                        verifier.oauth_token, verifier.oauth_token_secret)

    client.get_access_token(pin.strip())  # authorize with Twitter, after making sure no stray characters got in
    encoded = b64encode(image.getvalue())  # read bytes from image and encode for Twitter
    client.api.account.update_profile_image.post(image=encoded)  # upload the icon
Beispiel #5
0
def auth_verify(app):
    """
    Get final access token and secret, redirect   
    <app> = application identifier
    
    @oauth_verifier = parameter from auth_url callback (see above)  
    """
    try:
        # START DEBUG
        # if session values are in the AUTH CHECK but not here - be sure
        # to check cookie settings. Note: Firefox let's you select
        # "Accept Cookies" even when in "Always use private mode" -- however
        # cookies do not work in this mode.
        print 'AUTH_VERIFY', app
        for k, v in session.iteritems():
            print k, v
        # END DEBUG

        oauth_verifier = request.args.get('oauth_verifier')
        if not oauth_verifier:
            raise Exception('expected oauth_verifier parameter')

        auth_token = session_get(app, 'auth_token')
        auth_token_secret = session_get(app, 'auth_token_secret')
        auth_redirect = session_get(app, 'auth_redirect')

        if not (auth_token and auth_token_secret):
            raise Exception('Authorization credentials not found in session')

        tk = get_twitter_keys()
        client = UserClient(tk.consumer_key, tk.consumer_secret, auth_token,
                            auth_token_secret)
        token = client.get_access_token(oauth_verifier)

        session_set(app, 'access_token', token.oauth_token)
        session_set(app, 'access_token_secret', token.oauth_token_secret)
        session_pop_list(app,
                         ['auth_token', 'auth_token_secret', 'auth_redirect'])

        if auth_redirect:
            return redirect(auth_redirect)
        else:
            return redirect(url_for('home'))
    except Exception, e:
        traceback.print_exc()
        return redirect(auth_redirect)
Beispiel #6
0
def auth_verify():
    """
    Get final access token and secret, redirect       
    @oauth_verifier = parameter from auth_url callback (see above)  
    """
    try:
        # START DEBUG
        # if session values are in the AUTH CHECK but not here - be sure
        # to check cookie settings. Note: Firefox let's you select
        # "Accept Cookies" even when in "Always use private mode" -- however
        # cookies do not work in this mode.
        #print 'AUTH_VERIFY', app
        #for k, v in session.iteritems():
        #    print k, v
        # END DEBUG

        oauth_verifier = request.args.get('oauth_verifier')
        if not oauth_verifier:
            raise Exception('Expected oauth_verifier parameter')

        auth_token = session.get('auth_token')
        auth_token_secret = session.get('auth_token_secret')    
        auth_redirect = session.get('auth_redirect') or url_for('index')
        if not (auth_token and auth_token_secret):
            raise Exception('Authorization credentials not found in session')
    
        tk = config.get_twitter_keys()
        client = UserClient(tk.consumer_key, tk.consumer_secret,
                    auth_token, auth_token_secret)                    
        token = client.get_access_token(oauth_verifier)
        
        print token
        
        session['access_token'] = token.oauth_token
        session['access_token_secret'] = token.oauth_token_secret  
        session['screen_name'] = token.screen_name
        session_pop_list(['auth_token', 'auth_token_secret', 'auth_redirect'])
        
        return redirect(auth_redirect)
    except Exception, e:
        traceback.print_exc()
        return redirect(auth_redirect)
Beispiel #7
0
def registered_twitter(request):
	user = request.user
	platform = 'twitter'
	#Twitter Authorization p2
	ACCESS_TOKEN = request.session.get('ACCESS_TOKEN')
	ACCESS_TOKEN_SECRET = request.session.get('ACCESS_TOKEN_SECRET')
	client = UserClient(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
	OAUTH_VERIFIER = request.GET['oauth_verifier']
	token = client.get_access_token(OAUTH_VERIFIER)
	access_token = token.oauth_token
	access_token_secret = token.oauth_token_secret
	profile_name = token.screen_name
	Authorized_Accts.objects.create(
		user = user,
		platform = platform,
		profile_name = profile_name,
		access_token = access_token,
		access_token_secret = access_token_secret
	)
	return render(request, 'registered_twitter.html', {'platform': platform, 'profile_name': profile_name})
Beispiel #8
0
#!/usr/bin/env python
#To get twitter oauth tokens
#1. Get your consumer key and consumer secret from the app page on apps.twitter.com
#2. Use the birdy python library

from birdy.twitter import UserClient

key = raw_input("Consumer key: ")
secret = raw_input("Consumer secret: ")
client = UserClient(key, secret)
token = client.get_signin_token()
access_key = token.oauth_token
access_secret = token.oauth_token_secret
print token.auth_url
pin = raw_input("PIN: ")
client = UserClient(key, secret, access_key, access_secret)
client.get_access_token(pin)
print token
Beispiel #9
0
from config import *
from birdy.twitter import UserClient

# Use the client to generate the auth token and auth secret
client = UserClient(get_consumer_key(), get_consumer_secret())
token = client.get_authorize_token()
AUTH_TOKEN = token.oauth_token
AUTH_TOKEN_SECRET = token.oauth_token_secret

# Prompt the user to visit the auth URL
print "Go to the following URL to get the PIN: "
print token.auth_url

# Get PIN (OAUTH_VERIFIER) from user
OAUTH_VERIFIER = raw_input("Enter PIN: ")

# Use the client to generate the access token and access secret
client = UserClient(get_consumer_key(), get_consumer_secret(), AUTH_TOKEN,
                    AUTH_TOKEN_SECRET)
token = client.get_access_token(OAUTH_VERIFIER)

# Display OAUTH token and secret
print "Save these values in your application's config.py file: "
print "OAUTH_TOKEN = '" + token.oauth_token + "'"
print "OAUTH_TOKEN_SECRET = '" + token.oauth_token_secret + "'"