From 44c4eeca62d1ea9bf88142c86dc31835067ccb12 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sun, 20 Sep 2015 22:56:24 -0700 Subject: [PATCH] Updated README, added "persistant" option to config and command line. --- README.rst | 45 +++++++++++++++++++++------------------------ rtv/__main__.py | 12 ++++++------ rtv/config.py | 3 ++- rtv/oauth.py | 3 ++- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/README.rst b/README.rst index 4303ee5..12a515c 100644 --- a/README.rst +++ b/README.rst @@ -73,11 +73,8 @@ Basic Commands Authenticated Commands ---------------------- -Some actions require that you be logged in to your reddit account. To log in you can either: - -1. provide your username as a command line argument ``-u`` (your password will be securely prompted), or -2. press ``u`` while inside of the program - +Some actions require that you be logged in to your reddit account. +You can log in by pressing ``u`` while inside of the program. Once you are logged in your username will appear in the top-right corner of the screen. :``a``/``z``: Upvote/downvote @@ -147,12 +144,27 @@ If you prefer to stay in the terminal, use ``$BROWSER`` to specify a console-bas $ export BROWSER=w3m +----- +OAuth +----- + +OAuth support allows you to use reddit to authenticate on non-reddit websites and applications [#]_. OAuth replaces the deprecated cookie-based username/password authentication. + +RTV's login process follows the steps below: + +1. You initiate a login by pressing the ``u`` key. +2. You're redirected to a webbrowser where reddit will ask you to login and authorize RTV. +3. RTV uses the generated token to login on your behalf. +4. The token is stored on your computer at ``~/.config/rtv/refresh-token`` for future sessions. You can disable this by setting ``persistant=False`` in your RTV config. + +.. [#] ``_ + ----------- Config File ----------- RTV will read a configuration placed at ``~/.config/rtv/rtv.cfg`` (or ``$XDG_CONFIG_HOME``). -Each line in the files will replace the corresponding default argument in the launch script. +Each line in the file will replace the corresponding default argument in the launch script. This can be used to avoid having to re-enter login credentials every time the program is launched. Example initial config: @@ -175,24 +187,9 @@ Example initial config: # This may be necessary for compatibility with some terminal browsers # ascii=True ------ -OAuth ------ - -OAuth is an authentication standard, that replaces authentication with login and password. - -RTV implements OAuth. It stores OAuth configuration at ``~/.config/rtv/oauth.cfg``(or ``$XDG_CONFIG_HOME``). -**The OAuth configuration file must be writable, and is created automatically if it doesn't exist.** -It contains a boolean to trigger auto-login (defaults to false). -When authenticated, an additional field is written : **refresh_token**. -This acts as a replacement to username and password : it is used to authenticate you on Reddit servers. - -Example **oauth.cfg**: - -.. code-block:: ini - - [oauth] - auto_login=false + # Enable persistant storage of your authentication token + # This allows you to remain logged in when you restart the program + persistant=True === diff --git a/rtv/__main__.py b/rtv/__main__.py index 3cc8c6c..422f663 100644 --- a/rtv/__main__.py +++ b/rtv/__main__.py @@ -38,8 +38,8 @@ def command_line(): parser.add_argument('-l', dest='link', help='full URL of a submission that will be opened on start') parser.add_argument('--ascii', action='store_true', help='enable ascii-only mode') parser.add_argument('--log', metavar='FILE', action='store', help='log HTTP requests to a file') - parser.add_argument('--refresh-token', dest='refresh_token', help='OAuth refresh token') - parser.add_argument('--clear-session', dest='clear_session', action='store_true', help='Remove any saved OAuth tokens before starting') + parser.add_argument('--non-persistant', dest='persistant', action='store_false', help='Forget all authenticated users when the program exits') + parser.add_argument('--clear-auth', dest='clear_auth', action='store_true', help='Remove any saved OAuth tokens before starting') args = parser.parse_args() return args @@ -68,12 +68,12 @@ def main(): if args.ascii: config.unicode = False + if not args.persistant: + config.persistant = False if args.log: logging.basicConfig(level=logging.DEBUG, filename=args.log) - if args.clear_session: + if args.clear_auth: config.clear_refresh_token() - if args.refresh_token: - config.save_refresh_token(args.refresh_token) try: print('Connecting...') @@ -111,4 +111,4 @@ def main(): # Explicitly close file descriptors opened by Tornado's IOLoop tornado.ioloop.IOLoop.current().close(all_fds=True) -sys.exit(main()) \ No newline at end of file +sys.exit(main()) diff --git a/rtv/config.py b/rtv/config.py index 24eeec0..6d681e1 100644 --- a/rtv/config.py +++ b/rtv/config.py @@ -10,6 +10,7 @@ CONFIG = os.path.join(XDG_HOME, 'rtv', 'rtv.cfg') TOKEN = os.path.join(XDG_HOME, 'rtv', 'refresh-token') unicode = True +persistant = True # https://github.com/reddit/reddit/wiki/OAuth2 # Client ID is of type "installed app" and the secret should be left empty @@ -55,4 +56,4 @@ def save_refresh_token(token, filename=TOKEN): def clear_refresh_token(filename=TOKEN): if os.path.exists(filename): - os.remove(filename) \ No newline at end of file + os.remove(filename) diff --git a/rtv/oauth.py b/rtv/oauth.py index 4bd6122..88e4978 100644 --- a/rtv/oauth.py +++ b/rtv/oauth.py @@ -100,8 +100,9 @@ class OAuthTool(object): try: with self.loader(message='Logging in'): access_info = self.reddit.get_access_information(oauth_code) - config.save_refresh_token(access_info['refresh_token']) self.refresh_token = access_info['refresh_token'] + if config.persistant: + config.save_refresh_token(access_info['refresh_token']) except (praw.errors.OAuthAppRequired, praw.errors.OAuthInvalidToken): show_notification(self.stdscr, ['Invalid OAuth data']) else: