djapiauth/auth.py
def api_auth(function=None):
    """
    check:
    1, timestamp in reasonable range
    2, api key exists
    3, entry point allowed for this api key
    4, signature correctness

    effect:
    - add user object in request if the api key is binding with an user
    """
    def real_decorator(func):
        def wrapped(request, *args, **kwargs):
            try:
                user = _auth_url(request.get_full_path(), request.body)
                request.user = user  # put user object in request
            except Exception as e:
                return JsonResponse({"error": str(e)}, status=403)
            return func(request, *args, **kwargs)
        setattr(wrapped, '__djapiauth__', True)
        return wrapped
    return real_decorator if not function else real_decorator(function)
def api_auth(function=None):
    """
    check:
    1, timestamp in reasonable range
    2, api key exists
    3, entry point allowed for this api key
    4, signature correctness

    effect:
    - add user object in request if the api key is binding with an user
    """
    def real_decorator(func):
        def wrapped(request, *args, **kwargs):
            try:
                user = _auth_url(request.get_full_path(), request.body)
                request.user = user  # put user object in request
            except Exception as e:
                return JsonResponse({"error": str(e)}, status=403)
            return func(request, *args, **kwargs)
        setattr(wrapped, '__djapiauth__', True)
        return wrapped
    return real_decorator if not function else real_decorator(function)
check:
    1, timestamp in reasonable range
    2, api key exists
    3, entry point allowed for this api key
    4, signature correctness

    effect:
    - add user object in request if the api key is binding with an user