chiark
/
gitweb
/
~mdw
/
chopwood
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chpwd.js: Provide the CAPTUREP argument to `addEventListener'.
[chopwood]
/
httpauth.py
diff --git
a/httpauth.py
b/httpauth.py
index 22648dd4c09be34809b784fe4e52ec7e780a0bc8..13ba0d1155767a66de538942a6851f776d6ffdbb 100644
(file)
--- a/
httpauth.py
+++ b/
httpauth.py
@@
-175,6
+175,7
@@
LOGIN_REASONS = {
'EXPIRED': 'session timed out',
'BADTAG': 'incorrect tag',
'NOUSER': 'unknown user name',
'EXPIRED': 'session timed out',
'BADTAG': 'incorrect tag',
'NOUSER': 'unknown user name',
+ 'LOGOUT': 'explicitly logged out',
None: None
}
None: None
}
@@
-201,6
+202,9
@@
def check_auth(token, nonce = None):
global NONCE
global NONCE
+ ## If the token has been explicitly clobbered, then we're logged out.
+ if token == 'logged-out': raise AuthenticationFailed, 'LOGOUT'
+
## Parse the token.
bits = token.split('.', 3)
if len(bits) != 4: raise AuthenticationFailed, 'BADTOKEN'
## Parse the token.
bits = token.split('.', 3)
if len(bits) != 4: raise AuthenticationFailed, 'BADTOKEN'
@@
-227,6
+231,16
@@
def check_auth(token, nonce = None):
## Done.
return user
## Done.
return user
+def bake_cookie(value):
+ """
+ Return a properly baked authentication-token cookie with the given VALUE.
+ """
+ return CGI.cookie('chpwd-token', value,
+ httponly = True,
+ secure = CGI.SSLP,
+ path = CFG.SCRIPT_NAME,
+ max_age = (CFG.SECRETLIFE - CFG.SECRETFRESH))
+
###--------------------------------------------------------------------------
### Authentication commands.
###--------------------------------------------------------------------------
### Authentication commands.
@@
-257,11
+271,7
@@
def cmd_auth(u, pw):
CGI.redirect(CGI.action('login', why = 'AUTHFAIL'))
else:
t = mint_token(u)
CGI.redirect(CGI.action('login', why = 'AUTHFAIL'))
else:
t = mint_token(u)
- CGI.redirect(CGI.action('list'),
- set_cookie = CGI.cookie('chpwd-token', t,
- httponly = True,
- path = CFG.SCRIPT_NAME,
- max_age = (CFG.SECRETLIFE -
- CFG.SECRETFRESH)))
+ CGI.redirect(CGI.action('list', u),
+ set_cookie = bake_cookie(t))
###----- That's all, folks --------------------------------------------------
###----- That's all, folks --------------------------------------------------