简体   繁体   English

来自Django的POST请求,以使用Django验证应用程序

[英]POST request from Django to authenticate an application with Django

Ok, so this seems bad (and it probably is, but i have enough doubts at the moment that I want to try it). 好的,这似乎很糟糕(可能是这样,但是我现在有足够的疑问要尝试一下)。

I have a Django bases website with a jwplayer flash app embedded on one of the pages. 我有一个基于Django的网站,其中一个页面上嵌入了jwplayer Flash应用程序。 The user has to login to get at that page. 用户必须登录才能进入该页面。 The jwplayer just plays an icecast stream. jwplayer只是播放一个Icecast流。

What I would like/need to do is have it so that only authenticated users can get to the icecast server. 我想要/需要做的是拥有它,以便只有经过身份验证的用户才能访问Icecast服务器。 At the moment if they grab the url from the webpage, they can get to it fairly trivially. 目前,如果他们从网页中获取网址,则可以相当轻松地获取它。

Icecast can authenticate via POST which I've setup in a django view. Icecast可以通过我在django视图中设置的POST进行身份验证。

So what I want is for the flashplayer to send the username and password of the user that is logged in, to icecast, which will then authenticate with the same username and password. 因此,我希望Flashplayer将登录用户的用户名和密码发送到icecast,然后将使用相同的用户名和密码进行身份验证。

My problem is that django doesnt store the actual password, just a hash (a good thing) so I'm beginning to think that I cant really send the user and password to icecast for it to authenticate with. 我的问题是django不会存储实际的密码,而只是存储一个哈希(这是一件好事),因此我开始认为我无法真正将用户名和密码发送到icecast进行身份验证。

My other thoughts were to just send the username, and check if that person has already authenticated. 我的其他想法是只发送用户名,并检查该人是否已通过身份验证。

But this would allow someone to listen if someone was already logged in. 但是,如果有人已经登录,这将使某人能够收听。

Could I do something with a session variable or something? 我可以对会话变量执行某些操作吗?

Django guru's help me! Django大师帮我! Im open to all and any ideas. 我愿意接受所有想法。

Cheers 干杯

Mark. 标记。

Why not just have your flash player look for the Django session cookie and then validate against the web server that the user is logged in? 为什么不让您的Flash Player查找Django会话cookie,然后对照用户登录的Web服务器进行验证?

Add something like this to your urls: 在您的网址中添加以下内容:

(r'^loggedin/', logged_in_user),

Add a view something like this (not tested): 添加类似这样的视图(未经测试):

from django.http import HttpResponseForbidden
def logged_in_user(request):
    if request.user.is_authenticated():
        return HttpResponseForbidden()
    else:
        response = HttpResponse(mimetype='text/plain')
        response.write('ok')
        return response

Then just do a get on the /loggedin/ and check the return code, if it's 200 they are logged in if 401 they are not (assuming you are passing in the session cookies) 然后只需在/ loggedin /上进行获取并检查返回码,如果返回值为200,则返回401,否则返回登录状态(假设您正在传递会话cookie)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM