|
1 | | -from abc import ABC |
2 | | -from dataclasses import dataclass |
3 | | -from typing import Optional |
| 1 | +try: |
| 2 | + from bluesky_authentication.protocols import ( |
| 3 | + ExternalAuthenticator, |
| 4 | + InternalAuthenticator, |
| 5 | + UserSessionState, |
| 6 | + ) |
| 7 | +except ModuleNotFoundError: |
| 8 | + from abc import ABC |
| 9 | + from dataclasses import dataclass |
| 10 | + from typing import Optional |
4 | 11 |
|
5 | | -from fastapi import Request |
| 12 | + from fastapi import Request |
6 | 13 |
|
| 14 | + @dataclass |
| 15 | + class UserSessionState: |
| 16 | + """Data transfer class to communicate custom session state information.""" |
7 | 17 |
|
8 | | -@dataclass |
9 | | -class UserSessionState: |
10 | | - """Data transfer class to communicate custom session state information.""" |
| 18 | + user_name: str |
| 19 | + state: dict = None |
11 | 20 |
|
12 | | - user_name: str |
13 | | - state: dict = None |
| 21 | + class InternalAuthenticator(ABC): |
| 22 | + """Base class for authenticators that use username/password credentials.""" |
14 | 23 |
|
| 24 | + async def authenticate(self, username: str, password: str) -> Optional[UserSessionState]: |
| 25 | + raise NotImplementedError |
15 | 26 |
|
16 | | -class InternalAuthenticator(ABC): |
17 | | - """ |
18 | | - Base class for authenticators that use username/password credentials. |
| 27 | + class ExternalAuthenticator(ABC): |
| 28 | + """Base class for authenticators that use external identity providers.""" |
19 | 29 |
|
20 | | - Subclasses must implement the authenticate method which takes a username |
21 | | - and password and returns a UserSessionState on success or None on failure. |
22 | | - """ |
23 | | - |
24 | | - async def authenticate(self, username: str, password: str) -> Optional[UserSessionState]: |
25 | | - raise NotImplementedError |
26 | | - |
27 | | - |
28 | | -class ExternalAuthenticator(ABC): |
29 | | - """ |
30 | | - Base class for authenticators that use external identity providers. |
31 | | -
|
32 | | - Subclasses must implement the authenticate method which takes a FastAPI |
33 | | - Request object and returns a UserSessionState on success or None on failure. |
34 | | - """ |
35 | | - |
36 | | - async def authenticate(self, request: Request) -> Optional[UserSessionState]: |
37 | | - raise NotImplementedError |
| 30 | + async def authenticate(self, request: Request) -> Optional[UserSessionState]: |
| 31 | + raise NotImplementedError |
0 commit comments