rtwilio/views.py
def validate_twilio_signature(func=None, backend_name='twilio-backend'):
    """View decorator to validate requests from Twilio per http://www.twilio.com/docs/security."""

    def _dec(view_func):
        @functools.wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            backend = kwargs.get('backend_name', backend_name)
            config = settings.INSTALLED_BACKENDS[backend]['config']
            validator = RequestValidator(config['auth_token'])
            signature = request.META.get('HTTP_X_TWILIO_SIGNATURE', '')
            url = request.build_absolute_uri()
            body = {}
            if request.method == 'POST':
                body = request.POST
            require_validation = config.get('validate', True)
            if validator.validate(url, body, signature) or not require_validation:
                return view_func(request, *args, **kwargs)
            else:
                return HttpResponseBadRequest()
        return _wrapped_view

    if func is None:
        return _dec
    else:
        return _dec(func)
def validate_twilio_signature(func=None, backend_name='twilio-backend'):
    """View decorator to validate requests from Twilio per http://www.twilio.com/docs/security."""

    def _dec(view_func):
        @functools.wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            backend = kwargs.get('backend_name', backend_name)
            config = settings.INSTALLED_BACKENDS[backend]['config']
            validator = RequestValidator(config['auth_token'])
            signature = request.META.get('HTTP_X_TWILIO_SIGNATURE', '')
            url = request.build_absolute_uri()
            body = {}
            if request.method == 'POST':
                body = request.POST
            require_validation = config.get('validate', True)
            if validator.validate(url, body, signature) or not require_validation:
                return view_func(request, *args, **kwargs)
            else:
                return HttpResponseBadRequest()
        return _wrapped_view

    if func is None:
        return _dec
    else:
        return _dec(func)
def validate_twilio_signature ( func = None , backend_name = 'twilio-backend' ) : def _dec ( view_func ) : @ functools . wraps ( view_func , assigned = available_attrs ( view_func ) ) def _wrapped_view ( request , * args , * * kwargs ) : backend = kwargs . get ( 'backend_name' , backend_name ) config = settings . INSTALLED_BACKENDS [ backend ] [ 'config' ] validator = RequestValidator ( config [ 'auth_token' ] ) signature = request . META . get ( 'HTTP_X_TWILIO_SIGNATURE' , '' ) url = request . build_absolute_uri ( ) body = { } if request . method == 'POST' : body = request . POST require_validation = config . get ( 'validate' , True ) if validator . validate ( url , body , signature ) or not require_validation : return view_func ( request , * args , * * kwargs ) else : return HttpResponseBadRequest ( ) return _wrapped_view if func is None : return _dec else : return _dec ( func )
View decorator to validate requests from Twilio per http://www.twilio.com/docs/security.
View decorator to validate requests from Twilio per http : // www . twilio . com / docs / security .