Skip to content

login

Definition of basic-auth login/logout endpoints.

get_login_router()

Get the APIRouter for /auth/token/login/ and /auth/token/logout/

Source code in fractal_server/app/routes/auth/login.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def get_login_router() -> APIRouter:
    """
    Get the `APIRouter` for `/auth/token/login/` and `/auth/token/logout/`
    """
    settings = Inject(get_settings)
    router_login = APIRouter()
    router_login.include_router(
        fastapi_users.get_auth_router(token_backend),
        prefix="/token",
    )
    if settings.FRACTAL_DISABLE_BASIC_AUTH == "true":
        # Remove `/auth/token/login/`
        original_routes = router_login.routes[:]
        router_login.routes = [
            route
            for route in original_routes
            if not route.path.startswith("/token/login")
        ]

    # Add trailing slash to all routes paths
    for route in router_login.routes:
        if not route.path.endswith("/"):
            route.path = f"{route.path}/"

    return router_login