diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-04-16 10:20:52 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-04-16 10:20:52 +0300 |
commit | f7d161fcb6f111d0dc36b8d6252c0d7061bbc5ae (patch) | |
tree | 245ea04f641e955998fbb2cb99208ec9fbfd8f30 | |
parent | e68f237576d3b3ee119a5b4ee29f68d892d1dbaf (diff) | |
download | distixapi-f7d161fcb6f111d0dc36b8d6252c0d7061bbc5ae.tar.gz |
Start on functions to check authentication
-rw-r--r-- | distixapi/__init__.py | 1 | ||||
-rw-r--r-- | distixapi/authn.py | 18 | ||||
-rw-r--r-- | distixapi/authn_tests.py | 11 |
3 files changed, 30 insertions, 0 deletions
diff --git a/distixapi/__init__.py b/distixapi/__init__.py index 03a5053..d860521 100644 --- a/distixapi/__init__.py +++ b/distixapi/__init__.py @@ -1 +1,2 @@ from .version import __version__, __version_info__ +from .authn import AuthenticationError, get_credentials diff --git a/distixapi/authn.py b/distixapi/authn.py new file mode 100644 index 0000000..53816b6 --- /dev/null +++ b/distixapi/authn.py @@ -0,0 +1,18 @@ +# Functions for checking authantication for API clients. + + +def get_credentials(request): + '''Return username, password of API client. + + They're assumed to be conveyed in an Authorization header using + Basic Auth. + + ''' + + raise AuthenticationError('No Authorization header') + + + +class AuthenticationError(Exception): + + pass diff --git a/distixapi/authn_tests.py b/distixapi/authn_tests.py new file mode 100644 index 0000000..2a220ab --- /dev/null +++ b/distixapi/authn_tests.py @@ -0,0 +1,11 @@ +import unittest + +import distixapi + + +class GetCredentialsTests(unittest.TestCase): + + def test_raises_error_if_no_Authentication_header(self): + request = {} + with self.assertRaises(distixapi.AuthenticationError): + distixapi.get_credentials(request) |