def handler(fun, *args, **kwargs):
        error = None
        access_token = None
        if CSRF_TOKEN_REQUIRED:
            if 'state' not in request.args:
                error = FacebookError(message="`state` parameter is required. This request might have been initiated by an unauthorized third-party.", err="StateMissing")
            elif session['facebook_state'] != request.args['state']:
                error = FacebookError(message="`state` parameter does not match session value. This request might have been initiated by an unauthorized third-party.", err="StateMismatch")
            del session['facebook_state']
        elif 'error' in request.args:
            message = request.args.get('error_description')
            err = request.args.get('error')
            reason = request.args.get('error_reason')
            error = FacebookError(message=message, err=err, code=reason)
        elif 'code' not in request.args:
            error = FacebookError(message="`code` is a required parameter.", err="CodeMissing")

        if error is None:
            code = request.args.get('code')
            facebook = Facebook()
            response = facebook.oauth.access_token(code=code)
            access_token = response.access_token
            from ecl_facebook.signals import post_facebook_auth
            post_facebook_auth.send('ecl_facebook', token=access_token)

        return fun(access_token, error)
    def inner(request, *args, **kwargs):
        error = None
        access_token = None
        if 'error' in request.GET:
            message = request.GET.get('error_description')
            err = request.GET.get('error')
            reason = request.GET.get('error_reason')
            error = FacebookError(message=message, err=err, code=reason)
        elif 'code' not in request.GET:
            error = FacebookError(message="`code` is a required parameter.", err="CodeMissing")
        elif CSRF_TOKEN_REQUIRED:
            if 'facebook_state' not in request.session:
                error = FacebookError(message="`facebook_state` parameter missing in user session. You might want to restart the authentication flow.", err="StateMissing")
            elif 'state' not in request.GET:
                error = FacebookError(message="`state` parameter is required. This request might have been initiated by an unauthorized third-party.", err="StateMissing")
                del request.session['facebook_state']
            elif request.session['facebook_state'] != request.GET['state']:
                error = FacebookError(message="`state` parameter does not match session value. This request might have been initiated by an unauthorized third-party.", err="StateMismatch")
                del request.session['facebook_state']

        if error is None:
            code = request.GET.get('code')
            facebook = Facebook()
            response = facebook.oauth.access_token(code=code)
            try:
                access_token = response.access_token
            except AttributeError:
                access_token = response['access_token']

            from ecl_facebook.signals import post_facebook_auth
            post_facebook_auth.send('ecl_facebook', token=access_token)

        return fun(request, access_token, error, *args, **kwargs)