From 4d1f70b1e6c4c2d91ec9fae08c4f1e3be3afac2c Mon Sep 17 00:00:00 2001 From: Kyle Mahan Date: Sat, 7 Feb 2015 12:23:06 -0800 Subject: [PATCH] bugfix: use endpoint-for-function for more robust endpoint matching --- flask_micropub.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/flask_micropub.py b/flask_micropub.py index 711dba9..85aabd0 100644 --- a/flask_micropub.py +++ b/flask_micropub.py @@ -69,7 +69,8 @@ class MicropubClient: https://indieauth.com/auth if none is provided. """ redirect_url = flask.url_for( - self._authenticated_handler.func_name, _external=True) + self.flask_endpoint_for_function(self._authenticated_handler), + _external=True) return self._start_indieauth(me, redirect_url, next_url, None) def authorize(self, me, next_url=None, scope='read'): @@ -89,7 +90,8 @@ class MicropubClient: https://indieauth.com/auth if none is provided. """ redirect_url = flask.url_for( - self._authorized_handler.func_name, _external=True) + self.flask_endpoint_for_function(self._authorized_handler), + _external=True) return self._start_indieauth(me, redirect_url, next_url, scope) def _start_indieauth(self, me, redirect_url, next_url, scope): @@ -296,6 +298,12 @@ class MicropubClient: token_endpoint and token_endpoint['href'], micropub_endpoint and micropub_endpoint['href']) + @staticmethod + def flask_endpoint_for_function(func): + for endpt, view_func in flask.current_app.view_functions.items(): + if func == view_func: + return endpt + class AuthResponse: """Authorization response, passed to the authorized_handler endpoint.