40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import Any, Protocol
|
|
|
|
from .mock_provider import get_jwt_token as get_jwt_token_local
|
|
from .mock_provider import protect_application as protect_application_local
|
|
|
|
|
|
class AuthProvider(Protocol):
|
|
def get_token_data(self) -> dict[str, Any] | None: ...
|
|
|
|
|
|
class LocalMockProvider:
|
|
def get_token_data(self) -> dict[str, Any] | None:
|
|
protect_application_local(render_exit=False)
|
|
return get_jwt_token_local()
|
|
|
|
|
|
class RaisaProvider:
|
|
def get_token_data(self) -> dict[str, Any] | None:
|
|
from raisa_streamlit_oauth import (
|
|
get_jwt_token as get_jwt_token_raisa, # type: ignore[reportMissingImports]
|
|
)
|
|
from raisa_streamlit_oauth import (
|
|
protect_application as protect_application_raisa, # type: ignore[reportMissingImports]
|
|
)
|
|
|
|
protect_application_raisa(render_exit=False)
|
|
return get_jwt_token_raisa()
|
|
|
|
|
|
def build_auth_provider() -> AuthProvider:
|
|
location = os.getenv(
|
|
"OPENBAO__SETTINGS__LOCATION", os.getenv("LOCATION", "prod")
|
|
).lower()
|
|
if location == "local":
|
|
return LocalMockProvider()
|
|
return RaisaProvider()
|