<s> """<STR_LIT>""" <EOL> from flask import Flask , g <EOL> from flask_httpauth import HTTPBasicAuth , HTTPTokenAuth , MultiAuth <EOL> from werkzeug . security import generate_password_hash , check_password_hash <EOL> from itsdangerous import TimedJSONWebSignatureSerializer as JWT <EOL> app = Flask ( __name__ ) <EOL> app . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> jwt = JWT ( app . config [ '<STR_LIT>' ] , expires_in = <NUM_LIT> ) <EOL> basic_auth = HTTPBasicAuth ( ) <EOL> token_auth = HTTPTokenAuth ( '<STR_LIT>' ) <EOL> multi_auth = MultiAuth ( basic_auth , token_auth ) <EOL> users = { <EOL> "<STR_LIT>" : generate_password_hash ( "<STR_LIT:hello>" ) , <EOL> "<STR_LIT>" : generate_password_hash ( "<STR_LIT>" ) <EOL> } <EOL> for user in users . keys ( ) : <EOL> token = jwt . dumps ( { '<STR_LIT:username>' : user } ) <EOL> print ( '<STR_LIT>' . format ( user , token ) ) <EOL> @ basic_auth . verify_password <EOL> def verify_password ( username , password ) : <EOL> g . user = None <EOL> if username in users : <EOL> if check_password_hash ( users . get ( username ) , password ) : <EOL> g . user = username <EOL> return True <EOL> return False <EOL> @ token_auth . verify_token <EOL> def verify_token ( token ) : <EOL> g . user = None <EOL> try : <EOL> data = jwt . loads ( token ) <EOL> except : <EOL> return False <EOL> if '<STR_LIT:username>' in data : <EOL> g . user = data [ '<STR_LIT:username>' ] <EOL> return True <EOL> return False <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> @ multi_auth . login_required <EOL> def index ( ) : <EOL> return "<STR_LIT>" % g . user <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( ) </s>
