Skip to content

Commit 5b18532

Browse files
committed
✨ Implement login authentication module with routes for checking user authentication
1 parent 9ea68ef commit 5b18532

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

services/web/server/src/simcore_service_webserver/login_auth/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import logging
2+
3+
from aiohttp import web
4+
from aiohttp.web import RouteTableDef
5+
from servicelib.aiohttp import status
6+
7+
from .._meta import API_VTAG
8+
from ..login.decorators import login_required # FIXME: move this here
9+
10+
_logger = logging.getLogger(__name__)
11+
12+
13+
routes = RouteTableDef()
14+
15+
16+
@routes.get(f"/{API_VTAG}/auth:check", name="check_auth")
17+
@login_required
18+
async def check_auth(request: web.Request) -> web.Response:
19+
"""Lightweight endpoint for checking if users are authenticated & authorized to this product
20+
21+
Used primarily by Traefik auth middleware to verify session cookies
22+
SEE https://doc.traefik.io/traefik/middlewares/http/forwardauth
23+
"""
24+
# NOTE: for future development
25+
# if database access is added here, services like jupyter-math
26+
# which load a lot of resources will have a big performance hit
27+
# consider caching some properties required by this endpoint or rely on Redis
28+
assert request # nosec
29+
30+
return web.json_response(status=status.HTTP_204_NO_CONTENT)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
3+
from aiohttp import web
4+
from servicelib.aiohttp.application_setup import ModuleCategory, app_module_setup
5+
6+
from ..products.plugin import setup_products
7+
from ..rest.plugin import setup_rest
8+
from ..security.plugin import setup_security
9+
from . import _controller_rest
10+
11+
_logger = logging.getLogger(__name__)
12+
13+
14+
@app_module_setup(
15+
__name__, ModuleCategory.ADDON, settings_name="WEBSERVER_LOGIN_AUTH", logger=_logger
16+
)
17+
def setup_login_auth(app: web.Application):
18+
19+
setup_products(app)
20+
setup_security(app)
21+
setup_rest(app)
22+
23+
app.add_routes(_controller_rest.routes)

0 commit comments

Comments
 (0)