def login(): """Login to flickr with read only access.After successful login redirects to callback url else redirected to index page """ try: auth = AuthHandler(key=app.config['FLICKR_KEY'], secret=app.config['FLICKR_SECRET'], callback=url_for('flickr_callback', _external=True)) return redirect(auth.get_authorization_url('read')) except FlickrError, f: # Flash failed login & redirect to index page flash(u'Failed to authenticate user with flickr', 'error') return redirect(url_for('index'))
def protected_view(*args, **kwargs): if session.token: token = session.token #log.info('Getting token from session: %s' % token) return view(*args, **kwargs) else: # No valid token, so redirect to Flickr #log.info('Redirecting user to Flickr to get frob') #url = f.web_login_url(perms='read') a = AuthHandler(callback=CALLBACK_URL) url = a.get_authorization_url('read') session.a = a return redirect(url)
def init(key, secret): """ Initialize API. @see: http://www.flickr.com/services/api/ @param key: str, API key @param secret: str, API secret """ # TODO: save keys in file too, and share with download tool logging.debug('Initializing Flickr API ({0}/{1})'.format(key, secret)) Flickr.set_keys(key, secret) auth_file = os.path.expanduser(AUTH_FILE) logging.debug('Loading credentials from: {0}'.format(auth_file)) try: handler = AuthHandler.load(auth_file) set_auth_handler(handler) return except IOError: logging.warning('Could not load credentials from: {0}'.format(auth_file)) # fall through and create the file pass # Get new crendentials logging.debug('Retrieving new credentials from Flickr') handler = AuthHandler(key=key, secret=secret) print('Please authorize: {0}'.format(handler.get_authorization_url('write'))) # TODO: make landing page that extracts the verifier verifier = raw_input('Verifier: ') handler.set_verifier(verifier) try: handler.save(auth_file) except IOError: logging.warning('Could not save credentials to: {0}'.format(auth_file)) set_auth_handler(handler)