<s> import flask <EOL> import auth <EOL> import model <EOL> import util <EOL> from main import app <EOL> instagram_config = dict ( <EOL> access_token_method = '<STR_LIT:POST>' , <EOL> access_token_url = '<STR_LIT>' , <EOL> authorize_url = '<STR_LIT>' , <EOL> base_url = '<STR_LIT>' , <EOL> consumer_key = model . Config . get_master_db ( ) . instagram_client_id , <EOL> consumer_secret = model . Config . get_master_db ( ) . instagram_client_secret , <EOL> ) <EOL> instagram = auth . create_oauth_app ( instagram_config , '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def instagram_authorized ( ) : <EOL> response = instagram . authorized_response ( ) <EOL> if response is None : <EOL> flask . flash ( '<STR_LIT>' ) <EOL> return flask . redirect ( util . get_next_url ( ) ) <EOL> flask . session [ '<STR_LIT>' ] = ( response [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> user_db = retrieve_user_from_instagram ( response [ '<STR_LIT:user>' ] ) <EOL> return auth . signin_user_db ( user_db ) <EOL> @ instagram . tokengetter <EOL> def get_instagram_oauth_token ( ) : <EOL> return flask . session . get ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def signin_instagram ( ) : <EOL> return auth . signin_oauth ( instagram ) <EOL> def retrieve_user_from_instagram ( response ) : <EOL> auth_id = '<STR_LIT>' % response [ '<STR_LIT:id>' ] <EOL> user_db = model . User . get_by ( '<STR_LIT>' , auth_id ) <EOL> if user_db : <EOL> return user_db <EOL> return auth . create_user_db ( <EOL> auth_id = auth_id , <EOL> name = response . get ( '<STR_LIT>' , '<STR_LIT>' ) . strip ( ) or response . get ( '<STR_LIT:username>' ) , <EOL> username = response . get ( '<STR_LIT:username>' ) , <EOL> ) </s>
