- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将TokenAuthentication与我的一种 View 一起使用。
如https://www.django-rest-framework.org/api-guide/authentication/中所述,我在发送的请求中添加了从登录名中收到的 token ,并将其作为HTTP header 添加为“Authorization”。
问题是在我的单元测试中,身份验证失败。
查看TokenAuthentication类,我看到要检查的 header 是“HTTP_AUTHORIZATION”而不是“Authorization”
我正在使用的 View :
class DeviceCreate(generics.CreateAPIView):
model = Device
serializer_class = DeviceSerializer
authentication_classes = (TokenAuthentication,)
permission_classes = (IsAuthenticated,)
最佳答案
Looking into the TokenAuthentication class I see that the header being checked is 'HTTP_AUTHORIZATION' and not 'Authorization'
META
字典中进行查找时,它实际寻找的 header 没有前面的
HTTP_
,因此
request.META.get('HTTP_AUTHORIZATION', '')
实际上是在请求中查找
Authorization
header 。
The problem is that in my unittests the authentication fails Changing the header to 'HTTP_AUTHORIZATION' seems to work
HTTP_AUTHORIZATION
是您需要做的,等同于实际设置
Authorization
header 。如果您实际上发出了http请求,则应该发现设置auth header 的工作与您期望的完全一样。
request.META
文档:
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.META
request.META
中查找 header 的Django文档:
With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER.
However, you can use keywords arguments to specify some default headers. For example, this will send a
User-Agent
HTTP header in each request:c = Client(HTTP_USER_AGENT='Mozilla/5.0')
关于django - Django TokenAuthentication缺少 'Authorization' http header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15113248/
我目前有一个使用 Authorize.net 的 ARB API 的应用程序。我的一切都按照我认为应该的方式工作,但我真的很想收到来自 authorize.net 测试服务器 (test.author
Authorize.net 永远不会允许您退还同一天提交的交易。因此,编写一个创建交易然后退款的测试是很困难的。 我找不到通过 API 执行此操作的方法,因此: 我可以要求 Authorize.net
我想使用 createTransactionRequest 创建付款资料。 这是我传递的请求参数。 { "createTransactionRequest":{ "merchantA
我根据这个例子开发了我的mvc应用程序: https://github.com/AzureADSamples/WebApp-WebAPI-OpenIDConnect-DotNet 身份验证与 Azur
所以我正在尝试实现以下场景: 应用程序受基本身份验证保护。假设它托管在 app.com 上 在应用程序前面的 HTTP 代理也需要身份验证。它托管在 proxy.com 因此,用户必须在同一个请求中为
根据 ASP.NET website ASP.NET MVC 框架包括几个 Action 过滤器: OutputCache – 此操作过滤器将 Controller 操作的输出缓存一段指定的时间。 H
我正在发布一些 JSON 数据并添加一个 Authorization标题。但是,请求对象没有正确的授权属性。 HTTP_AUTHORIZATION和 headers两者都显示正确的授权详细信息。 {'
更改群集的IP配置(所有外部IP更改,内部专用IP保持不变)后,某些kubectl命令不再对任何容器起作用。 pods 全部启动并运行,似乎发现自己没有问题。这是输出: bronger@penny:~
Authorize.Net will be upgrading access to the Internet connections that serve our data centers. Inst
您好,我正在学习 HTML5,我想知道这两个元元素之间有什么区别? 最佳答案 第一个无效,http-equiv被枚举,即它有一组对其有效的值和author不是一个。 (它旨在作为一种将 pragm
我们想在应用商店中发布一个应用。为我们构建它的第 3 方需要我们通过苹果开发门户创建的证书和配置文件。根据文档,创建证书的方法是使用 mac 的钥匙串(keychain)应用程序,然后选择“从证书颁发
在同一项目中,在 Nancy 中使用任一 token 授权形式保护模块的最佳方法是什么?我需要两种类型的安全性,并且我不希望创建单独的应用程序:一种使用 Form 保护 View ,另一种用于使用 T
我正在尝试获取访问 token ,但是我收到了这个错误 {"error_description":"授权服务器不支持授权授予类型","error":"unsupported_grant_type"}
如何从一组“author”(User)中过滤出具有“author”的对象? “对象”是帖子,具有作者(ForeignKey 到用户)。 我对此非常困惑,所以我很感激能得到帮助。当然,人们可以通过手动过
我有三个 Kafka 经纪人( kafka_2.11-0.10.0.0 )每个经纪人的安全配置如下, listeners=PLAINTEXT://xxxx:9093,SASL_PLAINTEXT://
@IBOutlet weak var menuButton: UIButton! @IBOutlet weak var clubButton: UIButton! @IBOutlet weak var
我不知道如何执行以下查询。我有 3 张 table : song (song_id, title, is_draft) author (author_id, name) song_author (so
我正在使用 Thymeleaf、Spring-boot 和 Java。我有导航栏的 li 项目,并且想要为其中一个 li 项目设置访问权限,以便如果 LoggedUser.client.policyT
刚从使用 Books 应用程序示例的 Djangobook 教程中学习时,您通过多对多关系将 Book 与 Author 相关,并将 Book 与 Publisher 相关。您可以使用 p.book_
当我的应用程序启动 map View 时,我请求 iOS8“使用时”位置权限。假设用户同意。 仅当用户选择加入我的地理围栏功能时,我才想请求始终许可。但是调用 CLLocationManager.re
我是一名优秀的程序员,十分优秀!