Skip to content

Instantly share code, notes, and snippets.

@kylewm
Created May 11, 2016 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylewm/5484831548b32d8bce2b2bb20be402f9 to your computer and use it in GitHub Desktop.
Save kylewm/5484831548b32d8bce2b2bb20be402f9 to your computer and use it in GitHub Desktop.
#!/bin/python
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlencode, parse_qs
def get_endpoints(url):
r = requests.get(url)
soup = BeautifulSoup(r.text)
return [
soup.find(None, attrs={'rel': rel})['href']
for rel in ('authorization_endpoint', 'token_endpoint', 'micropub')
]
if __name__ == '__main__':
url = input('URL: ')
endpoints = get_endpoints(url)
params = {
'me': url,
'client_id': 'http://example.com/',
'scope': 'post',
'redirect_uri': 'https://kylewm.github.io/oob/',
'state': '123',
}
# direct them to the first endpoint
print('Please visit: ', endpoints[0] + '?' + urlencode(params))
code = input('IndieAuth code: ')
params['code'] = code
r = requests.post(endpoints[1], data=params)
print('response:', r.text)
access_token = parse_qs(r.text)['access_token'][0]
print("curl -i -H 'Authorization: Bearer {}' -d '...'".format(access_token))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment