Python rest_framework.authentication 模块,TokenAuthentication() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用rest_framework.authentication.TokenAuthentication()

项目:py2swagger    作者:Arello-Mobile    | 项目源码 | 文件源码
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
项目:journal-manager    作者:etesync    | 项目源码 | 文件源码
def reset(request):
    # Only run when in DEBUG mode! It's only used for tests
    if not settings.DEBUG:
        return HttpResponseBadRequest("Only allowed in debug mode.")

    if not request.user.is_authenticated():
        ret = TokenAuthentication().authenticate(request)

        if ret is None:
            return HttpResponseBadRequest("Couldn't authenticate")

        login(request, ret[0])

    # Only allow local users, for extra safety
    if not request.user.email.endswith('@localhost'):
        return HttpResponseBadRequest("Endpoint not allowed for user.")

    # Delete all of the journal data for this user for a clear test env
    request.user.journal_set.all().delete()
    request.user.journalmember_set.all().delete()
    try:
        request.user.userinfo.delete()
    except ObjectDoesNotExist:
        pass

    return HttpResponse()