SFM/app/auth/service.py
2026-06-04 15:20:29 +03:00

42 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
import streamlit as st
from .providers import build_auth_provider
def clear_session() -> None:
for key in list(st.session_state.keys()):
del st.session_state[key]
class AuthService:
def run(self) -> bool:
if "user_profile" in st.session_state:
return True
try:
token_data = build_auth_provider().get_token_data()
except ImportError:
st.error(
"Библиотека raisa_streamlit_oauth недоступна. "
"Для локальной разработки установите LOCATION=local."
)
return False
if not token_data:
return False
email = token_data.get("email")
if not email:
st.error(
"Не удалось идентифицировать пользователя: "
"в токене отсутствует поле email."
)
return False
st.session_state["token_data"] = token_data
st.session_state["user_profile"] = token_data
return True