mirror of
https://github.com/nova-r/fediplug.git
synced 2025-03-24 06:04:55 +01:00
Add the ability to use the browser auth flow
This commit is contained in:
parent
1be7fa4454
commit
432de9fc3c
1 changed files with 17 additions and 4 deletions
21
fediplay.py
21
fediplay.py
|
@ -79,6 +79,12 @@ def login(api_base_url, email, password):
|
||||||
client.log_in(email, password, to_file='usercred.secret')
|
client.log_in(email, password, to_file='usercred.secret')
|
||||||
umask(old_umask)
|
umask(old_umask)
|
||||||
|
|
||||||
|
def login_with_code(api_base_url, grant_code):
|
||||||
|
client = Mastodon(client_id='clientcred.secret', api_base_url=api_base_url)
|
||||||
|
old_umask = umask(0o77)
|
||||||
|
client.log_in(code=grant_code, to_file='usercred.secret')
|
||||||
|
umask(old_umask)
|
||||||
|
|
||||||
def stream(api_base_url):
|
def stream(api_base_url):
|
||||||
client = Mastodon(client_id='clientcred.secret', access_token='usercred.secret', api_base_url=api_base_url)
|
client = Mastodon(client_id='clientcred.secret', access_token='usercred.secret', api_base_url=api_base_url)
|
||||||
listener = StreamListener()
|
listener = StreamListener()
|
||||||
|
@ -111,7 +117,7 @@ def build_play_command(filename):
|
||||||
def main():
|
def main():
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from os import path
|
from os import path
|
||||||
from sys import exit
|
from sys import exit, argv
|
||||||
|
|
||||||
api_base_url = environ.get('FEDIPLAY_API_BASE_URL')
|
api_base_url = environ.get('FEDIPLAY_API_BASE_URL')
|
||||||
if not api_base_url:
|
if not api_base_url:
|
||||||
|
@ -124,9 +130,16 @@ def main():
|
||||||
|
|
||||||
if not path.exists('usercred.secret'):
|
if not path.exists('usercred.secret'):
|
||||||
print('==> No usercred.secret; logging in')
|
print('==> No usercred.secret; logging in')
|
||||||
email = input('Email: ')
|
if '-b' in argv or '--browser' in argv:
|
||||||
password = getpass('Password: ')
|
client = Mastodon(client_id='clientcred.secret', api_base_url=api_base_url)
|
||||||
login(api_base_url, email, password)
|
print("Open this page in your browser and follow the instructions to get the code you need, then paste it here")
|
||||||
|
print(client.auth_request_url())
|
||||||
|
grant_code = getpass('Code? ')
|
||||||
|
login_with_code(api_base_url, grant_code)
|
||||||
|
else:
|
||||||
|
email = input('Email: ')
|
||||||
|
password = getpass('Password: ')
|
||||||
|
login(api_base_url, email, password)
|
||||||
|
|
||||||
stream(api_base_url)
|
stream(api_base_url)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue