Browse Source

Interface for authentication providers

Alec Nikolas Reiter 7 years ago
parent
commit
8f1db85790
1 changed files with 32 additions and 0 deletions
  1. 32 0
      flaskbb/core/auth/authentication.py

+ 32 - 0
flaskbb/core/auth/authentication.py

@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+"""
+    flaskbb.core.auth.authentication
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    :copyright: (c) 2014-2018 the FlaskBB Team
+    :license: BSD, see LICENSE for more details
+"""
+
+from abc import abstractmethod
+
+from ..._compat import ABC
+from ..exceptions import BaseFlaskBBError
+
+
+class StopAuthentication(BaseFlaskBBError):
+    """
+    Used by Authentication providers to halt any further
+    attempts to authenticate a user.
+    """
+
+    def __init__(self, reason):
+        super(StopAuthentication, self).__init__(reason)
+        self.reason = reason
+
+
+class AuthenticationProvider(ABC):
+    @abstractmethod
+    def authenticate(self, identifier, secret):
+        pass
+
+    def __call__(self, identifier, secret):
+        return self.authenticate(identifier, secret)