简体   繁体   English

Django DRF 令牌认证通过 https/ssl

[英]Django DRF Token authentication over https/ssl

I'm trying to implement Djangos' rest framework token authentication working over https.我正在尝试在 https 上实现 Django 的 rest 框架令牌身份验证。 It works great over http but I can't get it working over https.它在 http 上运行良好,但我无法让它在 https 上运行。 On http I login, get my token and I can use that token for authentication with valid response.在 http 上,我登录,获取我的令牌,我可以使用该令牌进行有效响应的身份验证。

over https I can login, get back token successfully, However when I try to use that token for authenticate api requests over https, I get 401 unauthorized status code and response is通过 https 我可以登录,成功取回令牌,但是当我尝试使用该令牌通过 https 验证 api 请求时,我得到 401 未经授权的状态代码和响应
"detail": "Authentication credentials were not provided."

I followed this tutorial for http https://www.pythondecoders.com/2021/01/token-authentication-in-drf-django-rest.html#comment-form and http works fine.我按照本教程的 http https://www.pythondecoders.com/2021/01/token-authentication-in-drf-django-rest.html#comment-form和 Z80791B3AE7002FAA8C 工作正常。

I have been trying to look for answers but didn't see anything anywhere.我一直在寻找答案,但在任何地方都没有看到任何东西。 Is there any extra settings changes I need to make to make it work?我需要进行任何额外的设置更改才能使其正常工作吗?

Ok I was able to figure it out after many days.好的,我在很多天后才弄明白。 Hopefully it can help others.希望它可以帮助其他人。

I just needed to add below in my apache virtual host conf file我只需要在我的 apache 虚拟主机配置文件中添加以下内容

WSGIPassAuthorization on

Restart apache by below command通过以下命令重启 apache

sudo systemctl restart apache2

It worked for me.它对我有用。

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

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