<s> import flask <EOL> import auth <EOL> import config <EOL> import model <EOL> import util <EOL> from main import app <EOL> linkedin_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 = config . CONFIG_DB . linkedin_api_key , <EOL> consumer_secret = config . CONFIG_DB . linkedin_secret_key , <EOL> request_token_params = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:state>' : util . uuid ( ) , <EOL> } , <EOL> ) <EOL> linkedin = auth . create_oauth_app ( linkedin_config , '<STR_LIT>' ) <EOL> def change_linkedin_query ( uri , headers , body ) : <EOL> headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return uri , headers , body <EOL> linkedin . pre_request = change_linkedin_query <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def linkedin_authorized ( ) : <EOL> response = linkedin . 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> me = linkedin . get ( '<STR_LIT>' ) <EOL> user_db = retrieve_user_from_linkedin ( me . data ) <EOL> return auth . signin_user_db ( user_db ) <EOL> @ linkedin . tokengetter <EOL> def get_linkedin_oauth_token ( ) : <EOL> return flask . session . get ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def signin_linkedin ( ) : <EOL> return auth . signin_oauth ( linkedin ) <EOL> def retrieve_user_from_linkedin ( 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> names = [ response . get ( '<STR_LIT>' , '<STR_LIT>' ) , response . get ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> name = '<STR_LIT:U+0020>' . join ( names ) . strip ( ) <EOL> email = response . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return auth . create_user_db ( <EOL> auth_id = auth_id , <EOL> name = name , <EOL> username = email or name , <EOL> email = email , <EOL> verified = bool ( email ) , <EOL> ) </s>
