summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérôme Schneider <jschneider@entrouvert.com>2014-12-09 16:22:09 (GMT)
committerJérôme Schneider <jschneider@entrouvert.com>2015-01-27 10:59:32 (GMT)
commit6a43276c45fef0537c261ee44b687601393809d3 (patch)
tree23aa5325b8e203a3c52b989bd3fc56f55b8d67a9
parentbbbe4c5561063b61a8fba571cb1b0d5d25b62d14 (diff)
downloadmandaye-6a43276c45fef0537c261ee44b687601393809d3.zip
mandaye-6a43276c45fef0537c261ee44b687601393809d3.tar.gz
mandaye-6a43276c45fef0537c261ee44b687601393809d3.tar.bz2
authform: add an url to test credentials
post a json with post values on /mandaye/check/credentials and this request will return a json dict with a data entry OK or KO Closes #6127
-rw-r--r--mandaye/auth/authform.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/mandaye/auth/authform.py b/mandaye/auth/authform.py
index 642acb3..7f18f49 100644
--- a/mandaye/auth/authform.py
+++ b/mandaye/auth/authform.py
@@ -17,7 +17,7 @@ from mandaye import config, __version__
from mandaye.exceptions import MandayeException
from mandaye.log import logger
from mandaye.http import HTTPHeader, HTTPRequest
-from mandaye.response import _500, _302, _401, json_response, json_error
+from mandaye.response import _500, _302, _401, json_response, json_bad_request
from mandaye.server import get_response
from mandaye.backends.default import Association
@@ -70,6 +70,13 @@ a password_field key if you want to encode a password.")
def get_default_mapping(self):
mapping = [
{
+ 'path': r'%s$' % self.urls.get('check_credentials', '/mandaye/check/credentials'),
+ 'response': {
+ 'auth': 'check_identifiers',
+ 'method': 'POST',
+ }
+ },
+ {
'path': r'%s$' % self.urls.get('logout_url', '/mandaye/logout'),
'on_response': [{'auth': 'slo'}]
},
@@ -433,3 +440,48 @@ a password_field key if you want to encode a password.")
return True
return False
+ def check_credentials(self, env, values, request, response):
+ """
+ This method is designed to be called like a json webservice
+ The http client must make a POST with the following json :
+ {
+ "post_values": {
+ "foo": "bar",
+ "password": "monsecret",
+ "birthdate": "01/01/1970"
+ }
+ }
+ This method will response in json :
+ {"data": "OK|KO", err: 1|0 [,"err_msg": "blabla"]}
+ """
+ try:
+ content = json.loads(request.msg.read())
+ except ValueError:
+ return json_bad_request({
+ "data": "KO",
+ "err": 1,
+ "err_msg": "invalid json"
+ })
+ if not content.has_key('post_values'):
+ return json_bad_request({
+ "data": "KO",
+ "err": 1,
+ "err_msg": "post_values parameter missing"})
+ if not isinstance(content['post_values'], dict):
+ return json_bad_request({
+ "data": "KO",
+ "err": 1,
+ "err_msg": "post_values parameter must be a dictionary"
+ })
+ response = self.replay(env, content['post_values'])
+ if self.replay_condition and eval(self.replay_condition):
+ return json_response({
+ "data": "OK",
+ "err": 0
+ })
+ else:
+ return json_response({
+ "data": "KO",
+ "err": 0
+ })
+