From ddeb9f3403fdc5f2542b4fdf59c200d556c6c8a0 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Sat, 4 Apr 2015 12:28:32 -0300 Subject: [PATCH] Configurable blueprint url_prefix and auth endpoint. Fix #6 --- README.md | 3 +++ flask_pusher.py | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3da8b9c..3acfb89 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ from flask.ext.pusher import Pusher app = Flask(__name__) pusher = Pusher(app) +# Use pusher = Pusher(app, url_prefix="/yourpath") to mount the plugin in another path ``` The extension gives you two ways to access the pusher client: @@ -80,6 +81,8 @@ This function must return `True` for authorized and `False` for unauthorized users. It happens in the request context, so you have all `Flask` features, including for exemple the `Flask-Login` current user. +Set the `PUSHER_AUTH` configuration to change the auth endpoint. The default value is `/auth`. + ```python from flask.ext.login import current_user diff --git a/flask_pusher.py b/flask_pusher.py index 47f4f31..73f3a53 100644 --- a/flask_pusher.py +++ b/flask_pusher.py @@ -12,11 +12,11 @@ class Pusher(object): - def __init__(self, app=None): + def __init__(self, app=None, url_prefix="/pusher"): self.app = app self._auth_handler = None self._channel_data_handler = None - self._blueprint = Blueprint('pusher', __name__, url_prefix="/pusher") + self._blueprint = Blueprint('pusher', __name__, url_prefix=url_prefix) self.webhooks = Webhooks(self) if app is not None: @@ -29,6 +29,7 @@ def init_app(self, app): app.config.setdefault("PUSHER_SECRET", '') app.config.setdefault("PUSHER_HOST", '') app.config.setdefault("PUSHER_PORT", '') + app.config.setdefault("PUSHER_AUTH", '/auth') client = _pusher.Pusher( app_id=app.config["PUSHER_APP_ID"], @@ -38,7 +39,7 @@ def init_app(self, app): port=app.config["PUSHER_PORT"], encoder=getattr(app, "json_encoder", None)) - self._make_blueprint() + self._make_blueprint(app.config["PUSHER_AUTH"]) app.register_blueprint(self._blueprint) if not hasattr(app, "extensions"): @@ -57,10 +58,10 @@ def channel_data(self, handler): self._channel_data_handler = handler return handler - def _make_blueprint(self): + def _make_blueprint(self, auth_path): bp = self._blueprint - @bp.route("/auth", methods=["POST"]) + @bp.route(auth_path, methods=["POST"]) def auth(): if not self._auth_handler: abort(403)