SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 155 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from werkzeug.wrappers import Request, Response, ResponseStream
  2.  
  3. class middleware():
  4.     '''
  5.     Simple WSGI middleware
  6.     '''
  7.  
  8.     def __init__(self, app):
  9.         self.app = app
  10.         self.userName = 'Tony'
  11.         self.password = 'IamIronMan'
  12.  
  13.     def __call__(self, environ, start_response):
  14.         request = Request(environ)
  15.         userName = request.authorization['username']
  16.         password = request.authorization['password']
  17.        
  18.         # these are hardcoded for demonstration
  19.         # verify the username and password from some database or env config variable
  20.         if userName == self.userName and password == self.password:
  21.             environ['user'] = { 'name': 'Tony' }
  22.             return self.app(environ, start_response)
  23.  
  24.         res = Response(u'Authorization failed', mimetype= 'text/plain', status=401)
  25.         return res(environ, start_response)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top