You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

27 lines
927 B

from typing import Optional
from fastapi.responses import RedirectResponse
from nicegui import app, ui
from services.auth.oidc import oidc_config
import uuid
@ui.page('/login')
def login() -> Optional[RedirectResponse]:
if app.storage.user.get('authenticated', False):
return RedirectResponse('/')
def initiate_oidc_login():
# Generate state parameter for security
state = str(uuid.uuid4())
app.storage.user['oidc_state'] = state
# Get authorization URL and redirect
auth_url = oidc_config.get_authorization_url(state)
ui.navigate.to(auth_url, new_tab=False)
with ui.card().classes('absolute-center'):
ui.label('Authentication Required').classes('text-xl mb-4')
ui.label('Click below to login with your OIDC provider').classes('mb-4')
ui.button('Log in with OIDC', on_click=initiate_oidc_login).classes('w-full')
return None