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


Python authentication.TokenAuthentication方法代码示例

本文整理汇总了Python中rest_framework.authentication.TokenAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Python authentication.TokenAuthentication方法的具体用法?Python authentication.TokenAuthentication怎么用?Python authentication.TokenAuthentication使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rest_framework.authentication的用法示例。


在下文中一共展示了authentication.TokenAuthentication方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_authentication_introspectors

# 需要导入模块: from rest_framework import authentication [as 别名]
# 或者: from rest_framework.authentication import TokenAuthentication [as 别名]
def get_authentication_introspectors(view):
    """
    Get View Authentication Introspectors

    :param view: DjangoRestFramework View
    :return: list of authentication introspectors
    :rtype: list
    """
    from rest_framework import authentication
    authenticators_map = {
        authentication.BasicAuthentication: BasicAuthenticationIntrospector,
        authentication.TokenAuthentication: TokenAuthenticationIntrospector,
    }
    authenticators = getattr(view, 'authentication_classes', [])
    introspectors = []

    for authenticator in authenticators:
        introspectors.append(
            authenticators_map.get(authenticator, BaseAuthenticationIntrospector)(authenticator)
        )
    return introspectors 
开发者ID:Arello-Mobile,项目名称:py2swagger,代码行数:23,代码来源:authentication.py

示例2: authenticate

# 需要导入模块: from rest_framework import authentication [as 别名]
# 或者: from rest_framework.authentication import TokenAuthentication [as 别名]
def authenticate(self, request):
        auth_result = super(TokenAuthenticationWithChangeSet,
                            self).authenticate(request)
        # NOTE(xchu): The `auth_result` can be `None` if uncorrect
        #             authorization header is privided or nothing privided.
        if auth_result is None:
            return auth_result

        # NOTE(xchu): Update request.changeset.author if the author is None;
        #             That's because if we use `TokenAuthentication`,
        #             DRF do the TokenAuthentication after the request passed
        #             `ChangesetMiddleware` and all other Django middlewares.
        #             Which means that we will not have the user until `authenticate`
        #             here.
        if hasattr(request, "changeset") and request.changeset.author is None:
            # the `auth_result` is `None` or a (user, token) tuple.
            request.changeset.author = auth_result[0]
        return auth_result 
开发者ID:product-definition-center,项目名称:product-definition-center,代码行数:20,代码来源:authentication.py

示例3: get_authenticators

# 需要导入模块: from rest_framework import authentication [as 别名]
# 或者: from rest_framework.authentication import TokenAuthentication [as 别名]
def get_authenticators(self):
        try:
            from knox.auth import TokenAuthentication
        except ImportError:
            warnings.warn(
                'django-rest-knox must be installed for Knox authentication',
                ImportWarning,
            )
            raise

        return [TokenAuthentication()] 
开发者ID:st4lk,项目名称:django-rest-social-auth,代码行数:13,代码来源:views.py

示例4: authenticate_credentials

# 需要导入模块: from rest_framework import authentication [as 别名]
# 或者: from rest_framework.authentication import TokenAuthentication [as 别名]
def authenticate_credentials(self, key):
        """ Mostly duplicated from TokenAuthentication, except that we return
        an AnonymousUser """
        try:
            token = self.model.objects.get(key=key)
        except self.model.DoesNotExist:
            raise exceptions.AuthenticationFailed(_('Invalid token.'))
        return AnonymousUser(), token 
开发者ID:kobotoolbox,项目名称:kpi,代码行数:10,代码来源:authorized_application.py


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