Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve feedback for oauth errors. #888

Merged
merged 1 commit into from
May 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions jira/jirashell.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from jira import JIRA, __version__

CONFIG_PATH = os.path.join(os.path.expanduser("~"), ".jira-python", "jirashell.ini")
SENTINEL = object()


def oauth_dance(server, consumer_key, key_cert_data, print_tokens=False, verify=None):
Expand All @@ -34,8 +35,16 @@ def oauth_dance(server, consumer_key, key_cert_data, print_tokens=False, verify=
server + "/plugins/servlet/oauth/request-token", verify=verify, auth=oauth
)
request = dict(parse_qsl(r.text))
request_token = request["oauth_token"]
request_token_secret = request["oauth_token_secret"]
request_token = request.get("oauth_token", SENTINEL)
request_token_secret = request.get("oauth_token_secret", SENTINEL)
if request_token is SENTINEL or request_token_secret is SENTINEL:
problem = request.get("oauth_problem")
if problem is not None:
message = "OAuth error: {}".format(problem)
else:
message = " ".join(f"{key}:{value}" for key, value in request.items())
exit(message)

if print_tokens:
print("Request tokens received.")
print(" Request token: {}".format(request_token))
Expand Down