Support discovering endpoints from HTTP Link headers
in addition to searching the body of the page.
This commit is contained in:
parent
9fdd45a0de
commit
6c2f5f3f6a
|
@ -1,6 +1,11 @@
|
||||||
# Change Log
|
# Change Log
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
## 0.2.5 - 2016-01-27
|
||||||
### Changed
|
### Changed
|
||||||
- Bugfix: authorization_handler was burning the auth code by
|
- Bugfix: authorization_handler was burning the auth code by
|
||||||
|
|
|
@ -298,14 +298,23 @@ class MicropubClient:
|
||||||
if me_response.status_code != 200:
|
if me_response.status_code != 200:
|
||||||
return None, None, None
|
return None, None, None
|
||||||
|
|
||||||
soup = bs4.BeautifulSoup(me_response.text)
|
auth_endpoint = me_response.links.get('authorization_endpoint', {}).get('url')
|
||||||
auth_endpoint = soup.find('link', {'rel': 'authorization_endpoint'})
|
token_endpoint = me_response.links.get('token_endpoint', {}).get('url')
|
||||||
token_endpoint = soup.find('link', {'rel': 'token_endpoint'})
|
micropub_endpoint = me_response.links.get('micropub', {}).get('url')
|
||||||
micropub_endpoint = soup.find('link', {'rel': 'micropub'})
|
|
||||||
|
|
||||||
return (auth_endpoint and auth_endpoint['href'],
|
if not auth_endpoint or not token_endpoint or not micropub_endpoint:
|
||||||
token_endpoint and token_endpoint['href'],
|
soup = bs4.BeautifulSoup(me_response.text)
|
||||||
micropub_endpoint and micropub_endpoint['href'])
|
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
|
@staticmethod
|
||||||
def flask_endpoint_for_function(func):
|
def flask_endpoint_for_function(func):
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -11,7 +11,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='Flask-Micropub',
|
name='Flask-Micropub',
|
||||||
version='0.2.5',
|
version='0.2.6',
|
||||||
url='https://github.com/kylewm/flask-micropub/',
|
url='https://github.com/kylewm/flask-micropub/',
|
||||||
license='BSD',
|
license='BSD',
|
||||||
author='Kyle Mahan',
|
author='Kyle Mahan',
|
||||||
|
|
Loading…
Reference in New Issue