Skip to content

Commit

Permalink
Configurable blueprint url_prefix and auth endpoint. Fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio committed Apr 4, 2015
1 parent 2a05922 commit ddeb9f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions flask_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"],
Expand All @@ -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"):
Expand All @@ -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)
Expand Down

0 comments on commit ddeb9f3

Please sign in to comment.