Updated README, added "persistant" option to config and command line.

This commit is contained in:
Michael Lazar
2015-09-20 22:56:24 -07:00
parent 80bf45078a
commit 44c4eeca62
4 changed files with 31 additions and 32 deletions

View File

@@ -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.
.. [#] `<https://github.com/reddit/reddit/wiki/OAuth2>`_
-----------
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
===

View File

@@ -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...')

View File

@@ -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

View File

@@ -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: