'Sets a new CSRF token into the request and returns it.'

def new_csrf_token(self, request):

    token = self._token_factory()
    request.cookies[self.cookie_name] = token
    def set_cookie(request, response):
        self.cookie_profile.set_cookies(response, token)
    request.add_response_callback(set_cookie)
    return token
