当前位置: 首页>>代码示例>>Python>>正文


Python OAuthAuthentication.is_valid_request方法代码示例

本文整理汇总了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'
开发者ID:readingr,项目名称:provenance,代码行数:45,代码来源:auth.py


注:本文中的tastypie.authentication.OAuthAuthentication.is_valid_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。