Initial port to python3
[htsworkflow.git] / htsworkflow / frontend / auth.py
1 """
2 Define some alternate authentication methods
3 """
4 from django.core.exceptions import PermissionDenied
5 from django.conf import settings
6
7 apidata = {'apiid': '0', 'apikey': settings.DEFAULT_API_KEY}
8
9 def require_api_key(request):
10     # make sure we have the api component
11     if not ('apiid' in request.REQUEST or 'apikey' in request.REQUEST):
12         raise PermissionDenied
13
14     # make sure the id and key are right
15     if request.REQUEST['apiid'] == apidata['apiid'] and \
16        request.REQUEST['apikey'] == apidata['apikey']:
17         return True
18     else:
19         raise PermissionDenied
20         
21