MCPcopy Create free account
hub / github.com/SolSaviour/INFO1112-Materials / auth_basic

Function auth_basic

Week 6/server.py:3149–3166  ·  view source on GitHub ↗

Callback decorator to require HTTP auth (basic). TODO: Add route(check_auth=...) parameter.

(check, realm="private", text="Access denied")

Source from the content-addressed store, hash-verified

3147
3148
3149def auth_basic(check, realm="private", text="Access denied"):
3150 """ Callback decorator to require HTTP auth (basic).
3151 TODO: Add route(check_auth=...) parameter. """
3152
3153 def decorator(func):
3154
3155 @functools.wraps(func)
3156 def wrapper(*a, **ka):
3157 user, password = request.auth or (None, None)
3158 if user is None or not check(user, password):
3159 err = HTTPError(401, text)
3160 err.add_header('WWW-Authenticate', 'Basic realm="%s"' % realm)
3161 return err
3162 return func(*a, **ka)
3163
3164 return wrapper
3165
3166 return decorator
3167
3168# Shortcuts for common Bottle methods.
3169# They all refer to the current default application.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected