Skip to content

Commit 229bb85

Browse files
committed
First commit with common-auth flow
1 parent 94d8949 commit 229bb85

13 files changed

Lines changed: 88 additions & 1736 deletions

bluesky_httpserver/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
from fastapi import APIRouter, FastAPI, Request, Response
1515
from fastapi.middleware.cors import CORSMiddleware
1616
from fastapi.openapi.utils import get_openapi
17+
from bluesky_authentication.protocols import ExternalAuthenticator, InternalAuthenticator
1718

18-
from .authentication import ExternalAuthenticator, InternalAuthenticator
1919
from .console_output import CollectPublishedConsoleOutput, ConsoleOutputStream, SystemInfoStream
2020
from .core import PatchedStreamingResponse
2121
from .database.core import purge_expired
Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
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
411

5-
from fastapi import Request
12+
from fastapi import Request
613

14+
@dataclass
15+
class UserSessionState:
16+
"""Data transfer class to communicate custom session state information."""
717

8-
@dataclass
9-
class UserSessionState:
10-
"""Data transfer class to communicate custom session state information."""
18+
user_name: str
19+
state: dict = None
1120

12-
user_name: str
13-
state: dict = None
21+
class InternalAuthenticator(ABC):
22+
"""Base class for authenticators that use username/password credentials."""
1423

24+
async def authenticate(self, username: str, password: str) -> Optional[UserSessionState]:
25+
raise NotImplementedError
1526

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."""
1929

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

Comments
 (0)