如何设置tastypie的授权头? [英] How do I set the authorization header for tastypie?

查看:226
本文介绍了如何设置tastypie的授权头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在请求中传递值作为参数时,它起作用:

  curlhttp:// localhost:8080 / wordgame / api / v1 / rounds /?username = test_user& api_key = 12345678907a9cb56b7290223165e0a7c23623df& format = json

它不工作,当我尝试传递的值作为标题。这导致401:

  curl -H授权:ApiKey test_user:12345678907a9cb56b7290223165e0a7c23623df-HAccept:application / json http:// localhost:8080 / wordgame / api / v1 / rounds / 

我使用Tastypie < a href =http://django-tastypie.readthedocs.org/en/latest/authentication_authorization.html?highlight=ApiKey#apikeyauthentication =nofollow> ApiKeyAuthentication



尝试从github的版本,你的头看起来是正确的。

主分支,从PyPI安装的pip不会接受我的授权头。



我这样做:



pip install https://github.com/toastdriven/django-tastypie/tarball/master --upgrade


When passing values as parameters in the request it works:

curl "http://localhost:8080/wordgame/api/v1/rounds/?username=test_user&api_key=12345678907a9cb56b7290223165e0a7c23623df&format=json"

However, it does not work when I try to pass the values in as headers. This results in a 401:

curl -H "Authorization: ApiKey test_user:12345678907a9cb56b7290223165e0a7c23623df" -H "Accept: application/json" http://localhost:8080/wordgame/api/v1/rounds/

I am using Tastypie ApiKeyAuthentication

解决方案

Your header looks correct assuming the username/key are right..

Try the version from the github master branch, the one that pip installed from PyPI wouldn't accept the authorization header for me either.

I did this:

pip install https://github.com/toastdriven/django-tastypie/tarball/master --upgrade

这篇关于如何设置tastypie的授权头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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