本文整理汇总了Python中tastypie.authentication.OAuthAuthentication.is_valid_request方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthAuthentication.is_valid_request方法的具体用法?Python OAuthAuthentication.is_valid_request怎么用?Python OAuthAuthentication.is_valid_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.authentication.OAuthAuthentication
的用法示例。
在下文中一共展示了OAuthAuthentication.is_valid_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MultiAuthentication
# 需要导入模块: from tastypie.authentication import OAuthAuthentication [as 别名]
# 或者: from tastypie.authentication.OAuthAuthentication import is_valid_request [as 别名]
class MultiAuthentication(object):
"""
A custom authentication backend that supports anonymous access, OAuth authentication, and API key authentication.
"""
def __init__(self, **kwargs):
super(MultiAuthentication, self).__init__(**kwargs)
self.ApiKeyBackend = ApiKeyAuthentication()
self.OAuthBackend = OAuthAuthentication()
def is_authenticated(self, request, **kwargs):
"""
Identifies if the user is authenticated to continue or not.
Should return either ``True`` if allowed, ``False`` if not or an
``HttpResponse`` if you need something custom.
"""
if self.ApiKeyBackend.is_valid_request(request):
check = self.ApiKeyBackend.is_authenticated(request, **kwargs)
if check is True:
request._authentication_backend = self.ApiKeyBackend
return check
if self.OAuthBackend.is_valid_request(request):
check = self.OAuthBackend.is_authenticated(request, **kwargs)
if check is True:
request._authentication_backend = self.OAuthBackend
return check
else:
# Authenticate the request as the anonymous user
request.user = User.objects.get(id=ANONYMOUS_USER_ID)
return True
def get_identifier(self, request):
"""
Provides a unique string identifier for the requestor.
This implementation returns a combination of IP address and hostname.
"""
try:
return request._authentication_backend.get_identifier(request)
except AttributeError:
return 'nouser'