This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# coding=utf-8 | ||
|
||
import base64 | ||
|
||
from kuku import settings | ||
|
||
|
||
def require_basic_auth(func): | ||
|
||
def wrap(handler, *args, **kwargs): | ||
auth_header = handler.request.headers.get('Authorization') | ||
if auth_header is None or not auth_header.startswith('Basic '): | ||
handler.set_status(401) | ||
handler.set_header('WWW-Authenticate', 'Basic realm=Restricted') | ||
handler._transforms = [] | ||
handler.finish() | ||
return | ||
auth_decoded = base64.decodestring(auth_header[6:]) | ||
username, password = auth_decoded.split(':', 2) | ||
if (username, password) not in settings.ACCOUNTS: | ||
handler.set_status(403) | ||
handler.write('403') | ||
return | ||
return func(handler, *args, **kwargs) | ||
|
||
return wrap | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters