From 377fab789ee8f2f655aec481102cacbc0edf4ad4 Mon Sep 17 00:00:00 2001 From: David Champion Date: Sat, 5 May 2018 23:51:25 -0700 Subject: [PATCH] Prompt for developer token when login fails This is a reaction to jeffkowalski/geeknote #89. Evernote has revoked geeknote's API credentials, and for now at least it's necessary for each user individually to use a personal developer token. It's only necessary to provide it once, via environment, but that's still somewhat buried. This update detects when the OAuth temporary token api call fails, and prompts for a developer token. Once user has entered one, it's retained in the client settings database and doesn't need to be provided again. --- geeknote/geeknote.py | 18 ++++++++++++++++-- geeknote/oauth.py | 8 ++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/geeknote/geeknote.py b/geeknote/geeknote.py index a670547..6aaaed6 100755 --- a/geeknote/geeknote.py +++ b/geeknote/geeknote.py @@ -26,7 +26,7 @@ from editor import Editor, EditorThread from gclient import GUserStore as UserStore from argparser import argparser -from oauth import GeekNoteAuth +from oauth import GeekNoteAuth, OAuthError from storage import Storage from log import logging @@ -198,7 +198,21 @@ def checkAuth(self): def auth(self): GNA = GeekNoteAuth() - self.authToken = GNA.getToken() + try: + self.authToken = GNA.getToken() + except OAuthError as exc: + out.preloader.stop() + print exc.message + + import getpass + token = getpass.getpass("If you have an Evernote developer token, " + "enter it here: ") + if token: + self.authToken = token + else: + logging.error("No token service and no dev token.") + return False + userInfo = self.getUserInfo() if not isinstance(userInfo, object): logging.error("Could not get user info.") diff --git a/geeknote/oauth.py b/geeknote/oauth.py index 842f2e1..c0007d7 100644 --- a/geeknote/oauth.py +++ b/geeknote/oauth.py @@ -16,6 +16,10 @@ from log import logging +class OAuthError(Exception): + '''Generic OAuth exception''' + + class GeekNoteAuth(object): consumerKey = config.CONSUMER_KEY @@ -200,12 +204,12 @@ def getTmpOAuthToken(self): if response.status != 200: logging.error("Unexpected response status on get " "temporary oauth_token 200 != %s", response.status) - tools.exitErr() + raise OAuthError('OAuth token request failed') responseData = self.parseResponse(response.data) if 'oauth_token' not in responseData: logging.error("OAuth temporary not found") - tools.exitErr() + raise OAuthError('OAuth token request failed') self.tmpOAuthToken = responseData['oauth_token']