Apache 403通过HTML5视频播放器加载视频

2024-05-14 20:13:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Django应用程序,可以流式传输视频。该应用程序使用drf_firebase_auth。我使用Postman(Python请求库)和HTML5视频播放器(在登录过程后使用cookie身份验证)测试了流式视频

当应用程序在本地运行时,当Postman、Python请求库和HTML5播放器调用时,视频流可以工作。当应用程序在AWS上运行时,视频流通过Postman和Python请求库工作,但在尝试通过HTML5视频播放器进行流时,它使用403失败

在调试期间,我将print语句放入drf_firebase_auth代码中。当视频流化时(即通过邮递员或Python请求),print语句出现在apache错误日志中,但从HTML5播放器调用时不会出现。这似乎表明403是在到达Django之前发生的

欢迎提供调试指导

谢谢


Tags: djangoauth应用程序视频过程cookie流式语句
1条回答
网友
1楼 · 发布于 2024-05-14 20:13:52

我的问题是误解了一些Django身份验证过程,忘记清除cookie,以及drf_firebase_auth包不支持cookie身份验证

为了在使用drf_firebase_auth时支持cookie身份验证,我扩展了包并重写了get_token函数。修改了get_token函数,以便在找不到授权标头时查找授权cookie

这样做对吗

import  sys, os

import drf_firebase_auth.authentication

from drf_firebase_auth.settings import api_settings
from drf_firebase_auth.settings import api_settings
from rest_framework import (
    authentication,
    exceptions
)
from django.utils.encoding import smart_text

class FirebaseCookieAuthentication (drf_firebase_auth.authentication.FirebaseAuthentication):

    def get_token(self, request):
        """
        Parse Authorization header and retrieve JWT
        """
        authorization_header = \
            authentication.get_authorization_header(request).split()
        auth_header_prefix = api_settings.FIREBASE_AUTH_HEADER_PREFIX.lower()

        #changed code begins

        if not authorization_header or len (authorization_header) != 2:
            for k, v in request.COOKIES.items():
                if k.lower() == "authorization":
                    authorization_header = v.split (' ', 1)
                    break

        #changed code ends

        if not authorization_header or len(authorization_header) != 2:
            raise exceptions.AuthenticationFailed(
                'Invalid Authorization header format, expecting: JWT <token>.'
            )

        if smart_text(authorization_header[0].lower()) != auth_header_prefix:
            raise exceptions.AuthenticationFailed(
                'Invalid Authorization header prefix, expecting: JWT.'
            )

        return authorization_header[1]

谢谢

相关问题 更多 >

    热门问题