(view, request, test_func, realm="", *args, **kwargs)
return auth_request()
This is a helper function used by both 'require_valid_user' and
    'has_perm_or_basicauth' that does the nitty of determining if they
    are already logged in or if they have provided proper http-authorization
    and returning the view if all goes well, otherwise responding with a 401.
This is a helper function used by both 'require_valid_user' and
    'has_perm_or_basicauth' that does the nitty of determining if they
    are already logged in or if they have provided proper http-authorization
    and returning the view if all goes well, otherwise responding with a 401.
This is a helper function used by both require_valid_user and has_perm_or_basicauth that does the nitty of determining if they are already logged in or if they have provided proper http - authorization and returning the view if all goes well otherwise responding with a 401 .
def view_or_basicauth(view, request, test_func, realm="", *args, **kwargs):
    """
    This is a helper function used by both 'require_valid_user' and
    'has_perm_or_basicauth' that does the nitty of determining if they
    are already logged in or if they have provided proper http-authorization
    and returning the view if all goes well, otherwise responding with a 401.
    """
    if test_func(request.user):
        # Already logged in, just return the view.
        return view(request, *args, **kwargs)

    # They are not logged in. See if they provided login credentials

    # the AUTHORIZATION header is used when passing auth-headers
    # from Aapache to fcgi
    auth = None
    for h in ("AUTHORIZATION", "HTTP_AUTHORIZATION"):
        auth = request.META.get(h, auth)

    if not auth:
        return auth_request()

    auth = auth.split(None, 1)

    if len(auth) == 2:
        auth_type, credentials = auth

        # NOTE: We are only support basic authentication for now.
        if auth_type.lower() == "basic":
            try:
                credentials = (
                    base64.b64decode(credentials).decode("utf-8").split(":", 1)
                )

            except (UnicodeDecodeError, binascii.Error) as e:
                return HttpResponseBadRequest(
                    "Could not decode credentials: {msg}".format(msg=str(e))
                )

            if len(credentials) == 2:
                uname, passwd = credentials
                user = authenticate(username=uname, password=passwd)
                if user is not None and user.is_active:
                    login(request, user)
                    request.user = user

                    return view(request, *args, **kwargs)

    return auth_request()
def view_or_basicauth ( view , request , test_func , realm = "" , * args , * * kwargs ) : if test_func ( request . user ) : # Already logged in, just return the view. return view ( request , * args , * * kwargs ) # They are not logged in. See if they provided login credentials # the AUTHORIZATION header is used when passing auth-headers # from Aapache to fcgi auth = None for h in ( "AUTHORIZATION" , "HTTP_AUTHORIZATION" ) : auth = request . META . get ( h , auth ) if not auth : return auth_request ( ) auth = auth . split ( None , 1 ) if len ( auth ) == 2 : auth_type , credentials = auth # NOTE: We are only support basic authentication for now. if auth_type . lower ( ) == "basic" : try : credentials = ( base64 . b64decode ( credentials ) . decode ( "utf-8" ) . split ( ":" , 1 ) ) except ( UnicodeDecodeError , binascii . Error ) as e : return HttpResponseBadRequest ( "Could not decode credentials: {msg}" . format ( msg = str ( e ) ) ) if len ( credentials ) == 2 : uname , passwd = credentials user = authenticate ( username = uname , password = passwd ) if user is not None and user . is_active : login ( request , user ) request . user = user return view ( request , * args , * * kwargs ) return auth_request ( )