开发者

Authentication using chrome extension and Django

开发者 https://www.devze.com 2023-04-05 18:16 出处:网络
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 als开发者

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 als开发者_运维技巧o login and become active? Thanks.


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

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

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 for reading cookie:

mycookie = document.cookie(your_cookie_name);
0

精彩评论

暂无评论...
验证码 换一张
取 消