为tastypeapi提供oauth服务

django-tastypie-oauth的Python项目详细描述


Django Tastypie OAuth
===========

[![构建状态](https://travis-ci.org/orcasgit/django-tastype-oauth.svg?branch=master)(https://travis-ci.org/orcasgit/django-tastype-oauth)[![覆盖状态](https://coveralls.io/repos/orcasgit/django-tastype-oauth/badge.png?branch=master)(https://coveralls.io/r/orcasgit/django-tastype-oauth?branch=master)[![需求状态](https://requires.io/github/orcasgit/django-tastype-oauth/requirements.png?branch=master)(https://requires.io/github/orcasgit/django-tastype-oauth/requirements/?branch=master)


必须安装其中之一:
-django oauth toolkit:https://github.com/evonove/django oauth toolkit
-django-oauth2-provider:https://github.com/caffinehit/django-oauth2-provider

继续使用之前,请设置其中一个库。在django的“installed_apps”中添加“tastype_oauth”。
2.在django设置中指定“oauth_access_token_model”。此时,它可以是django oauth工具包的“oauth2_provider.models.accesstoken”,django-oauth2-provider的“provider.oauth2.models.accesstoken”。
3。创建tastype资源时,请使用“oauth20authentication”,如下所示:

``python
mysite/polls/api.py
从tastype.resources导入modelresource
从tastype.authorization导入djangoauthorization
从polls.models导入poll,choice
来自tastypice导入字段
来自tastypice_auth.authentication导入oauth20authentication


class choiceResource(modelResource):
class meta:
queryset=choice.objects.all()
resource_name='choice'
authorization=djangauthorization()
authentication=oauth20authentication()

class poll resource(modelresource):
choices=fields.tomanyfield(choiceResource,“choice_set”,full=true)
class meta:
queryset=poll.objects.all()
resource_name='poll'
authorization=djangauthorization()
authentication=oauth20authentication()
````
,或者,如果要使用作用域身份验证,使用来自tastypice\u oauth的“oauth2scopedauthentication”类:
``python
。使用django oauth工具包导入oauth2scopedauthentication

资源名称='choice'
queryset=choice.objects.all()
authorization=djangoauthorization()
authorization=oauth2scopedauthentication(
post=(“读写”,),
get=(“读”,
put=(“读”,“write”)

````
``python
从provider.constants导入read,write,read-write
从tastypeu oauth.authentication导入oauth2scopedauthentication

使用django-oauth2-provider
类choiceResource(modelResource):
poll=fields.toonefield(“polls.api.pollResource”,“poll”,full=false)
类元:
资源名称='choice'
查询集=choice.objects.all()
授权=djangoauthorization()
身份验证=OAuth2ScopedAuthentication(
post=(读写),
get=(读,),
输入=(读,写)

````
4。在授权用户并获得访问令牌之后,您可以像以前一样使用api,只需做一个小的更改。必须添加带有访问令牌的“oauth_consumer_key”get或post参数作为val或者将访问令牌放在“授权”头中。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何访问ArrayList中对象的特定元素   反射如何检查java。朗。反思。方法返回类型是集合?   当我想使用socket发送对象时出现Java异常   eclipse是否可以修补部署到Tomcat/WildFly的Java应用程序?   java Spring:无法导入库   java从基类请求体DTO获取派生DTO   向ArrayList中添加元素时引发java异常   算法Java程序从列表中给定的数字中分组连续数<list>   java如何从类中获取一个变量到主活动?   regex Java模式,用于双引号或单引号内的数据,不包括括号内的引号   类Java OOP物理引擎类型   java在使用Camel时,如何使用Spring加载属性?   java Junit 4在@Mock中的作用域生成方法