使用Chrome扩展程序和Django的认证 [英] Authentication using chrome extension and Django

查看:103
本文介绍了使用Chrome扩展程序和Django的认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些谁是熟悉Django和Chrome扩展程序。你是怎么做到使用cookie身份验证,这样,当您登录到您的网站在Django做,您的浏览器扩展程序也将登录并激活?谢谢你。

For those who is familiar with django and chrome extension. How do you do an authentication using cookies, such that when you login to your website made in django, your chrome extension will also login and become active? Thanks.

推荐答案

您的Chrome扩展程序(通过JavaScript),可以读取你的Django应用程序创建的cookie中。

Your Chrome extension (through Javascript) can read the cookie created by your Django application.

您可以使用的 Middelware 的类设置你的cookies,然后在JavaScript中读取它(在你的.js Chrome扩展文件)。

You can set your cookies using a Middelware class and then read it in JavaScript (in your .js Chrome extension file).

Python的code:

Python code:

class CookieMiddelware:
    def process_request(self, request):
        cookie = request.COOKIES.get(your_cookie_name)
        if cookie and not request.user.is_authenticated():
            // authenticate user here

JavaScript的code读取cookie的:

JavaScript code for reading cookie:

mycookie = document.cookie(your_cookie_name);

这篇关于使用Chrome扩展程序和Django的认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆