Skip to content

Commit

Permalink
Better error msg for token validation (#7159)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
zachliu and github-actions[bot] authored Sep 14, 2024
1 parent fb1a056 commit 5cf0b7b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions redash/handlers/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def get_google_auth_url(next_path):


def render_token_login_page(template, org_slug, token, invite):
error_message = None
try:
user_id = validate_token(token)
org = current_org._get_current_object()
Expand All @@ -39,19 +40,19 @@ def render_token_login_page(template, org_slug, token, invite):
user_id,
org_slug,
)
error_message = "Your invite link is invalid. Bad user id in token. Please ask for a new one."
except SignatureExpired:
logger.exception("Token signature has expired. Token: %s, org=%s", token, org_slug)
error_message = "Your invite link has expired. Please ask for a new one."
except BadSignature:
logger.exception("Bad signature for the token: %s, org=%s", token, org_slug)
error_message = "Your invite link is invalid. Bad signature. Please double-check the token."

if error_message:
return (
render_template(
"error.html",
error_message="Invalid invite link. Please ask for a new one.",
),
400,
)
except (SignatureExpired, BadSignature):
logger.exception("Failed to verify invite token: %s, org=%s", token, org_slug)
return (
render_template(
"error.html",
error_message="Your invite link has expired. Please ask for a new one.",
error_message=error_message,
),
400,
)
Expand Down

0 comments on commit 5cf0b7b

Please sign in to comment.