diff --git a/CHANGELOG.md b/CHANGELOG.md index 3afed46..30910b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to this project will be documented in this file. +## 0.2.6 - 2016-03-18 +### Changed +- Support discovering endpoints from HTTP Link headers in addition + to searching the body of the page. + ## 0.2.5 - 2016-01-27 ### Changed - Bugfix: authorization_handler was burning the auth code by diff --git a/flask_micropub.py b/flask_micropub.py index e25e6aa..d36b52e 100644 --- a/flask_micropub.py +++ b/flask_micropub.py @@ -298,14 +298,23 @@ class MicropubClient: if me_response.status_code != 200: return None, None, None - soup = bs4.BeautifulSoup(me_response.text) - auth_endpoint = soup.find('link', {'rel': 'authorization_endpoint'}) - token_endpoint = soup.find('link', {'rel': 'token_endpoint'}) - micropub_endpoint = soup.find('link', {'rel': 'micropub'}) + auth_endpoint = me_response.links.get('authorization_endpoint', {}).get('url') + token_endpoint = me_response.links.get('token_endpoint', {}).get('url') + micropub_endpoint = me_response.links.get('micropub', {}).get('url') - return (auth_endpoint and auth_endpoint['href'], - token_endpoint and token_endpoint['href'], - micropub_endpoint and micropub_endpoint['href']) + if not auth_endpoint or not token_endpoint or not micropub_endpoint: + soup = bs4.BeautifulSoup(me_response.text) + if not auth_endpoint: + auth_link = soup.find('link', {'rel': 'authorization_endpoint'}) + auth_endpoint = auth_link and auth_link['href'] + if not token_endpoint: + token_link = soup.find('link', {'rel': 'token_endpoint'}) + token_endpoint = token_link and token_link['href'] + if not micropub_endpoint: + micropub_link = soup.find('link', {'rel': 'micropub'}) + micropub_endpoint = micropub_link and micropub_link['href'] + + return auth_endpoint, token_endpoint, micropub_endpoint @staticmethod def flask_endpoint_for_function(func): diff --git a/setup.py b/setup.py index 0e70b60..e30704c 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ from setuptools import setup setup( name='Flask-Micropub', - version='0.2.5', + version='0.2.6', url='https://github.com/kylewm/flask-micropub/', license='BSD', author='Kyle Mahan',