def _do_redirect(request): oauth = OAuthApi(settings.TWITTER['CONSUMER_KEY'], settings.TWITTER['CONSUMER_SECRET']) request_token = oauth.getRequestToken() request.session['duration'] = request.POST['duration'] request.session['twitter_request_token'] = request_token authorization_url = oauth.getAuthorizationURL(request_token) return redirect(authorization_url)
def Auth(request): """docstring for Auth""" twitter = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET) request_token = twitter.getRequestToken() authorization_url = twitter.getAuthorizationURL(request_token) request.session['request_token'] = request_token return HttpResponseRedirect(authorization_url)
def generate(self): # get the bitly information self.getValueFromUser('BITLY_USER', "bit.ly username: "******"api key from 'http://bit.ly/a/account': ") # get the twitter information from oauthtwitter import OAuthApi twitter = OAuthApi(self.__APP_KEY, self.__APP_SECRET) temp_creds = twitter.getRequestToken() print "visit '%s' and write the pin:" \ % twitter.getAuthorizationURL(temp_creds) oauth_verifier = sys.stdin.readline().strip() access_token = twitter.getAccessToken(temp_creds, oauth_verifier) config['TWIT_TOKEN'] = access_token['oauth_token'] config['TWIT_SECRET'] = access_token['oauth_token_secret'] # get the svn information self.getValueFromUser('SVN_FS_ROOT', "Root directory for svn: ", '/svn/') self.getValueFromUser('SVN_TRAC_FORMAT', "Format for trac svn urls: ", "http://trac.edgewall.org/changeset/%d") # write out the configuration handle = open(filename, 'w') keys = self.__config__.keys() keys.sort() for key in keys: handle.write("%s='%s'\n" % (key, config[key])) handle.write("def normalizeUser(user):\n") handle.write(" return user\n") pphandle.close()
def Auth(request): """docstring for Auth""" twitter=OAuthApi(CONSUMER_KEY,CONSUMER_SECRET) request_token=twitter.getRequestToken() authorization_url=twitter.getAuthorizationURL(request_token) request.session['request_token']=request_token return HttpResponseRedirect(authorization_url)
def get_access_token(window): auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET) request_token = auth_api.getRequestToken() authorization_url = auth_api.getAuthorizationURL(request_token) webbrowser.open(authorization_url) auth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token) dialog = gtk.Dialog("Enter PIN", window, gtk.DIALOG_MODAL, (gtk.STOCK_OK, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) entry = gtk.Entry() dialog.vbox.pack_start(entry) entry.show() response = dialog.run() dialog.hide() if response == gtk.RESPONSE_OK: pin = entry.get_text() try: access_token = auth_api.getAccessToken(pin) except HTTPError: access_token = None return access_token else: return None
def begin_handshake( self, request ): twitter = OAuthApi( TWITTER_KEY, TWITTER_SECRET ) request.session[ 'request_token' ] = twitter.getRequestToken() redirect_url = twitter.getAuthorizationURL(request.session[ 'request_token' ] ) redirect_url = redirect_url[0:redirect_url.find( 'oauth_callback=None' )-2] redirect_url = redirect_url.replace( 'http://twitter.com/oauth/authorize', 'http://twitter.com/oauth/authenticate' ) return HttpResponseRedirect( redirect_url )
def auth(request): logger = get_fe_logger() logger.info('On auth') if not request.session.has_key('gprofileusername'): logger.debug('User doesnt have session on auth(), redirecting to /') return HttpResponseRedirect('/') twitter = OAuthApi(settings.CONSUMER_KEY, settings.CONSUMER_SECRET) request_token = twitter.getRequestToken() request.session['request_token'] = request_token.to_string() authorization_url = twitter.getAuthorizationURL(request_token) logger.debug('Sending user to authorization URL %s' % authorization_url) return HttpResponseRedirect(authorization_url)
def auth(): authToken = None authSecret = None if os.path.exists('/tmp/twitter.tmp'): f = open('/tmp/twitter.tmp', 'r') authToken = f.readline().strip() authSecret = f.readline().strip() print "oauth_token: " + authToken print "oauth_token_secret: " + authSecret f.close() needAuth = True if authToken!=None and authSecret!=None: twitter = OAuthApi(consumerKey, consumerSecret, authToken, authSecret) if twitter.autorized(): needAuth = False if needAuth: twitter = OAuthApi(consumerKey, consumerSecret) temp_credentials = twitter.getRequestToken() print temp_credentials print twitter.getAuthorizationURL(temp_credentials) oauth_verifier = raw_input('What is the PIN? ') access_token = twitter.getAccessToken(temp_credentials, oauth_verifier) print access_token print("oauth_token: " + access_token['oauth_token']) print("oauth_token_secret: " + access_token['oauth_token_secret']) f = open('/tmp/twitter.tmp', 'w') f.write('%s\n%s'%(access_token['oauth_token'], access_token['oauth_token_secret'])) f.close() twitter = OAuthApi(consumerKey, consumerSecret, access_token['oauth_token'], access_token['oauth_token_secret']) return twitter
def initiate_login(request): if request.method != 'POST': r = HttpResponse() r.status_code = 405 return r oauth = OAuthApi( settings.D51_DJANGO_AUTH['TWITTER']['CONSUMER_KEY'], settings.D51_DJANGO_AUTH['TWITTER']['CONSUMER_SECRET'] ) request_token = oauth.getRequestToken() request.session['twitter_request_token'] = request_token authorization_url = oauth.getAuthorizationURL(request_token) return redirect(authorization_url)
def initiate_login(request, redirect_field_name = auth.REDIRECT_FIELD_NAME): if request.method != 'POST': r = HttpResponse() r.status_code = 405 return r oauth = OAuthApi( settings.D51_DJANGO_AUTH['TWITTER']['CONSUMER_KEY'], settings.D51_DJANGO_AUTH['TWITTER']['CONSUMER_SECRET'] ) request_token = oauth.getRequestToken() request.session['twitter_request_token'] = request_token request.session['redirect_to'] = request.REQUEST.get(redirect_field_name, '/') authorization_url = oauth.getAuthorizationURL(request_token) return redirect(authorization_url)
def get_user_tokens(app_key, app_secret_key): if not os.path.isfile("../terminitter.oauth"): # no user tokens found, create some twitter = OAuthApi(app_key, app_secret_key) temp_credentials = twitter.getRequestToken() print(twitter.getAuthorizationURL(temp_credentials)) oauth_verifier = raw_input("Go the the URL above, and paste the PIN here: ") tokens = twitter.getAccessToken(temp_credentials, oauth_verifier) oauthf = open("../terminitter.oauth", "w") oauthf.write(tokens["oauth_token"] + "\n" + tokens["oauth_token_secret"]) oauthf.close() return [access_token["oauth_token"], access_token["oauth_token_secret"]] else: # read user tokens from file oauthf = open("../terminitter.oauth", "r") oauth_tokens = oauthf.read().splitlines() return [oauth_tokens[0], oauth_tokens[1]]
def _authorizeBootstrap(self): """ """ oauth_api = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET) request_token = oauth_api.getRequestToken() pin = self.guiHandle.requestAuthPin(oauth_api.getAuthorizationURL(request_token)) if (not pin) or (isinstance(pin, str) and not pin.isdigit()): # I rather do this ugly check than catch this later and have no clue # of what is causing the erro raise AuthFail("The retrieved pin is not valid") self._access_token = OAuthApi(CONSUMER_KEY, CONSUMER_SECRET, request_token).getAccessToken(pin) # Lets write this access token to a filename to reload it next time # Lets check if directory .tnt exists directory = os.environ["HOME"] + "/.tnt" if not (os.path.exists(directory) and os.path.isdir(directory)): os.mkdir(directory) file = open(ACCESS_TOKEN_FILENAME, "w") pickle.dump(self._access_token, file) file.close()
def setup(self): os.system('clear') twitter = OAuthApi(self.consumer_key, self.consumer_secret) # Get the temporary credentials for our next few calls temp_credentials = twitter.getRequestToken() # User pastes this into their browser to bring back a pin number print(twitter.getAuthorizationURL(temp_credentials)) # Get the pin # from the user and get our permanent credentials oauth_verifier = raw_input('What is the PIN? ') access_token = twitter.getAccessToken(temp_credentials, oauth_verifier) self.token = access_token['oauth_token'] self.secret = access_token['oauth_token_secret'] self.latest = 1 self.mention = 1 print 'Clitwi was successfully set up.'
def get(self): # check session session = self.get_vaild_session(extend=False) if session: self.delete_session(session) # get request token twit = OAuthApi() try: req_token = twit.getRequestToken() except DownloadError: self.redirect_error(msg="twitter is over capacity") return # return url control return_url = urllib.unquote(self.request.get('return_url')) # insert request token into DB fetcher.put_req_token(req_token.key, req_token.secret, return_url) # redirect user to twitter auth page auth_url = twit.getAuthorizationURL(req_token) self.redirect(auth_url)
def obtainAuth(self): twitter = OAuthApi(self.OAuthConsumerKey, self.OAuthConsumerSecret) # Get the temporary credentials for our next few calls temp_credentials = twitter.getRequestToken() # User pastes this into their browser to bring back a pin number print(twitter.getAuthorizationURL(temp_credentials)) # Get the pin # from the user and get our permanent credentials oauth_verifier = raw_input('What is the PIN? ') access_token = twitter.getAccessToken(temp_credentials, oauth_verifier) self.OAuthUserToken = access_token['oauth_token'] self.OAuthUserTokenSecret = access_token['oauth_token_secret'] print("\n===========================") print("To prevent this authorization process next session, " + "add the following lines to the [twitter] section of " + "your .trackupdaterc:") print("OAuthUserToken: " + self.OAuthUserToken) print("OAuthUserTokenSecret: " + self.OAuthUserTokenSecret) print("===========================\n")
def login_with_oauth(request): api = OAuthApi(settings.CONSUMER_KEY, settings.CONSUMER_SECRET) request_token = api.getRequestToken() request.session["request_token"] = request_token.to_string() authorization_url = api.getAuthorizationURL(request_token) return HttpResponseRedirect(authorization_url)
config.read(os.path.join(os.path.dirname(__file__), '../cfg.ini')) from oauthtwitter import OAuthApi import pprint import iemdb MESOSITE = iemdb.connect('mesosite', bypass=True) mcursor = MESOSITE.cursor() twitter = OAuthApi(config.get('twitter','consumerkey'), config.get('twitter', 'consumersecret')) # Get the temporary credentials for our next few calls temp_credentials = twitter.getRequestToken() # User pastes this into their browser to bring back a pin number print(twitter.getAuthorizationURL(temp_credentials)) # Get the pin # from the user and get our permanent credentials oauth_verifier = raw_input('What is the PIN? ') access_token = twitter.getAccessToken(temp_credentials, oauth_verifier) print("oauth_token: " + access_token['oauth_token']) print("oauth_token_secret: " + access_token['oauth_token_secret']) botuser = raw_input("What is username?") mcursor.execute("DELETE from oauth_tokens where username = '******'" % (botuser,)) mcursor.execute("INSERT into oauth_tokens values ('%s','%s','%s')" % (botuser, access_token['oauth_token'], access_token['oauth_token_secret']) ) mcursor.close()
from oauth import oauth from oauthtwitter import OAuthApi import pprint consumer_key = "" # TODO put your consumer_key consumer_secret = "" # TODO put your consumer_secret twitter = OAuthApi(consumer_key, consumer_secret) # Get the temporary credentials for our next few calls temp_credentials = twitter.getRequestToken() # User pastes this into their browser to bring back a pin number print(twitter.getAuthorizationURL(temp_credentials)) # Get the pin # from the user and get our permanent credentials oauth_verifier = raw_input('What is the PIN? ') access_token = twitter.getAccessToken(temp_credentials, oauth_verifier) print("oauth_token: " + access_token['oauth_token']) print("oauth_token_secret: " + access_token['oauth_token_secret'])
#!/usr/bin/env python from oauthtwitter import OAuthApi from settings import OAUTH_SETTINGS twitter = OAuthApi(OAUTH_SETTINGS['consumer_key'], OAUTH_SETTINGS['consumer_secret']) credenciales = twitter.getRequestToken() print twitter.getAuthorizationURL(credenciales) pin = input('INGRESA TU PIN: ') access_token = twitter.getAccessToken(credenciales, pin) print "OAuth Token: " + access_token['oauth_token'] print "OAuth Token Secret: " + access_token['oauth_token_secret']
elif sys.argv[1]=='--show' : print 'Registred users: ' for x in userlist: print x elif sys.argv[1]=='--authenticate' : if len(sys.argv)==2: strexmisc.help_message(1) quit() #Standard Oauth authentication twitter = OAuthApi(consumer_key, consumer_secret) # Get the temporary credentials for our next few calls temp_credentials = twitter.getRequestToken() # Open in firefox or user pastes this into their browser to bring back a pin number magic_URL=twitter.getAuthorizationURL(temp_credentials) print(magic_URL) os.system('firefox '+magic_URL) # Get the pin # from the user and get our permanent credentials oauth_verifier = raw_input('What is the PIN? ') access_token = twitter.getAccessToken(temp_credentials, oauth_verifier) # Add user to database user_data=open(os.path.join(c_folder,'login.info'),'a') user_data.write(sys.argv[2]+'&'+'token:'+access_token['oauth_token'] +'&'+'stoken:'+access_token['oauth_token_secret'] +'&'+'lstat:'+'0''\n') user_data.close() elif sys.argv[1]=='--help': # Full help message strexmisc.help_message(2)
def GetRequest(self): vOauthApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET) self.mOauthRequestToken = vOauthApi.getRequestToken( self.REQUEST_TOKEN_URL) self.mOauthRequestUrl = vOauthApi.getAuthorizationURL( self.mOauthRequestToken)
def get(self, action): # Depending on the action requested /admin/<action>/ if action == 'register': # Register a Twitter user with the application using # OAuth. Works with the Option model to store the request and # access tokens. # Remove all the previous tokens matching oauth-* from the datastore. options = Option.all() options.filter('name >=', 'oauth-').filter('name <', 'oauth-' + u'\ufffd') options.fetch(1000) for option in options: option.delete() # Request an OAuth token and show the authorization URL on Twitter. twitter = OAuthApi(consumer_key, consumer_secret) credentials = twitter.getRequestToken() url = twitter.getAuthorizationURL(credentials) rendertext(self, '<a href="%s">%s</a><br />' % (url, url)) rendertext( self, '<form action="/admin/verify/" method="GET"><input type="text" name="oauth_verifier" /><input type="submit" /></form>' ) # Save the tokens to the datastore for later authentication oauth_token = credentials['oauth_token'] oauth_token_secret = credentials['oauth_token_secret'] # Record the tokens opt = Option(name='oauth-request-token', value=oauth_token) opt.put() opt = Option(name='oauth-request-token-secret', value=oauth_token_secret) opt.put() elif action == 'verify': # Used to verify an initiated registration request. Request tokens should # by now be stored in the data store. Retrieve them and initiate a change. twitter = OAuthApi(consumer_key, consumer_secret) oauth_verifier = self.request.get('oauth_verifier') options = Option.all() options.filter('name =', 'oauth-request-token') oauth_token = options.get() options = Option.all() options.filter('name =', 'oauth-request-token-secret') oauth_token_secret = options.get() # Form a request and ask Twitter to exchange request tokens for access tokens using # an OAuth verifier (PIN code). credentials = { 'oauth_token': oauth_token.value, 'oauth_token_secret': oauth_token_secret.value, 'oauth_callback_confirmed': 'true' } credentials = twitter.getAccessToken(credentials, oauth_verifier) # Record the access tokens and remove the previously stored request tokens. access_token = Option(name='oauth-access-token', value=credentials['oauth_token']) access_token_secret = Option( name='oauth-access-token-secret', value=credentials['oauth_token_secret']) oauth_token.delete() oauth_token_secret.delete() access_token.put() access_token_secret.put() # Tokens are now saved, getTwitterObject can be used. self.response.out.write("You are now registered as @%s!" % credentials['screen_name']) # Uses the Task Queues API elif action == 'cron': if self.request.get('task') == 'geocode': for i in range(2, 140, 2): deferred.defer(tasks.geocode, _countdown=i, _queue='geocoding') rendertext(self, "Geo task added to queue")
def get_auth_url(): twitter = OAuthApi(settings.consumer_key, settings.consumer_secret) temp_credentials = twitter.getRequestToken() return temp_credentials,twitter.getAuthorizationURL(temp_credentials)
def GetRequest(self): vOauthApi = OAuthApi(self.CONSUMER_KEY, self.CONSUMER_SECRET) self.mOauthRequestToken = vOauthApi.getRequestToken(self.REQUEST_TOKEN_URL) self.mOauthRequestUrl = vOauthApi.getAuthorizationURL(self.mOauthRequestToken)
def get(self, action): # Depending on the action requested /admin/<action>/ if action == 'register': # Register a Twitter user with the application using # OAuth. Works with the Option model to store the request and # access tokens. # Remove all the previous tokens matching oauth-* from the datastore. options = Option.all() options.filter('name >=', 'oauth-').filter('name <', 'oauth-' + u'\ufffd') options.fetch(1000) for option in options: option.delete() # Request an OAuth token and show the authorization URL on Twitter. twitter = OAuthApi(consumer_key, consumer_secret) credentials = twitter.getRequestToken() url = twitter.getAuthorizationURL(credentials) rendertext(self, '<a href="%s">%s</a><br />' % (url, url)) rendertext(self, '<form action="/admin/verify/" method="GET"><input type="text" name="oauth_verifier" /><input type="submit" /></form>') # Save the tokens to the datastore for later authentication oauth_token = credentials['oauth_token'] oauth_token_secret = credentials['oauth_token_secret'] # Record the tokens opt = Option(name='oauth-request-token', value=oauth_token) opt.put() opt = Option(name='oauth-request-token-secret', value=oauth_token_secret) opt.put() elif action == 'verify': # Used to verify an initiated registration request. Request tokens should # by now be stored in the data store. Retrieve them and initiate a change. twitter = OAuthApi(consumer_key, consumer_secret) oauth_verifier = self.request.get('oauth_verifier') options = Option.all() options.filter('name =', 'oauth-request-token') oauth_token = options.get() options = Option.all() options.filter('name =', 'oauth-request-token-secret') oauth_token_secret = options.get() # Form a request and ask Twitter to exchange request tokens for access tokens using # an OAuth verifier (PIN code). credentials = {'oauth_token': oauth_token.value, 'oauth_token_secret': oauth_token_secret.value, 'oauth_callback_confirmed': 'true'} credentials = twitter.getAccessToken(credentials, oauth_verifier) # Record the access tokens and remove the previously stored request tokens. access_token = Option(name='oauth-access-token', value=credentials['oauth_token']) access_token_secret = Option(name='oauth-access-token-secret', value=credentials['oauth_token_secret']) oauth_token.delete() oauth_token_secret.delete() access_token.put() access_token_secret.put() # Tokens are now saved, getTwitterObject can be used. self.response.out.write("You are now registered as @%s!" % credentials['screen_name']) # Uses the Task Queues API elif action == 'cron': if self.request.get('task') == 'geocode': for i in range(2, 140, 2): deferred.defer(tasks.geocode, _countdown=i, _queue='geocoding') rendertext(self, "Geo task added to queue")