Callback decorator to require HTTP auth (basic). TODO: Add route(check_auth=...) parameter.
(check, realm="private", text="Access denied")
| 3147 | |
| 3148 | |
| 3149 | def 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. |
nothing calls this directly
no outgoing calls
no test coverage detected