【问题标题】:Apache 403 loading video through HTML5 Video playerApache 403 通过 HTML5 视频播放器加载视频
【发布时间】:2020-07-24 23:47:48
【问题描述】:

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

当应用程序在本地运行时,通过 Postman、Python 请求库和 HTML5 播放器调用视频流即可工作。当应用程序在 AWS 上运行时,视频流通过 Postman 和 Python 请求库工作,但在尝试通过 HTML5 视频播放器流式传输时失败并出现 403。

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

感谢任何调试指导。

谢谢。

【问题讨论】:

    标签: python html django amazon-web-services apache


    【解决方案1】:

    我的问题是误解了一些 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]
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 2011-04-05
      • 2013-05-06
      • 2017-04-18
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      相关资源
      最近更新 更多