Skip to content

Commit

Permalink
Alow mediafile access of anonymous user
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel committed May 21, 2024
1 parent d3df886 commit 5cdf548
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import requests
from authlib import (
ANONYMOUS_USER,
AUTHENTICATION_HEADER,
COOKIE_NAME,
AuthenticateException,
Expand All @@ -15,15 +14,15 @@
from .exceptions import ServerError


def check_login():
def check_login_valid():
"""Returns whether the user is logged in or not."""
auth_handler = AuthHandler(app.logger.debug)
cookie = request.cookies.get(COOKIE_NAME, "")
try:
user_id = auth_handler.authenticate_only_refresh_id(parse.unquote(cookie))
except (AuthenticateException, InvalidCredentialsException):
return False
return user_id != ANONYMOUS_USER
return True


def check_file_id(file_id, presenter_headers):
Expand Down
4 changes: 2 additions & 2 deletions src/mediaserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from flask import Flask, Response, jsonify, redirect, request

from .auth import AUTHENTICATION_HEADER, check_file_id, check_login
from .auth import AUTHENTICATION_HEADER, check_file_id, check_login_valid
from .config_handling import init_config, is_dev_mode
from .database import Database
from .exceptions import BadRequestError, HttpError, NotFoundError
Expand Down Expand Up @@ -35,7 +35,7 @@ def handle_view_error(error):

@app.route("/system/media/get/<int:file_id>")
def serve(file_id):
if not check_login():
if not check_login_valid():
return redirect("/")

# get file id
Expand Down

0 comments on commit 5cdf548

Please sign in to comment.