From 203ca33736570591ad196bf1da1156e986ac9a5c Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Mon, 2 Oct 2023 14:46:47 +0200 Subject: [PATCH] add auth type to param to cp auth NHUB-389 --- server/cp/auth.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/server/cp/auth.py b/server/cp/auth.py index 6e1d9ef..990f68f 100644 --- a/server/cp/auth.py +++ b/server/cp/auth.py @@ -8,7 +8,11 @@ from newsroom.types import AuthProviderType from newsroom.auth import get_company, get_user_by_email -from newsroom.auth.utils import sign_user_by_email, get_company_auth_provider, send_token +from newsroom.auth.utils import ( + sign_user_by_email, + get_company_auth_provider, + send_token, +) from newsroom.auth.views import logout as _logout from .password_reset_form import PasswordResetForm @@ -23,7 +27,7 @@ @blueprint.route("/auth_token") def token(): claims = None - token = flask.request.args.get('token') + token = flask.request.args.get("token") if token: try: claims = google.oauth2.id_token.verify_firebase_token( @@ -37,7 +41,9 @@ def token(): return flask.redirect(flask.url_for("auth.login", token_error=1)) email = claims["email"] - return sign_user_by_email(email, validate_login_attempt=True) + return sign_user_by_email( + email, auth_type=AuthProviderType.GOOGLE_OAUTH, validate_login_attempt=True + ) return flask.redirect(flask.url_for("auth.login")) @@ -79,11 +85,17 @@ def render_reset_page(error_str: Optional[str] = None): auth_provider = get_company_auth_provider(company) if auth_provider["auth_type"] != AuthProviderType.PASSWORD.value: - return render_reset_page(gettext("Password reset for your account is not supported through Newshub")) + return render_reset_page( + gettext( + "Password reset for your account is not supported through Newshub" + ) + ) # Send standard Newshub reset password email if not send_token(user, "reset_password"): - return render_reset_page(gettext("An error occurred while sending reset password email")) + return render_reset_page( + gettext("An error occurred while sending reset password email") + ) return flask.redirect(flask.url_for("cp.auth.reset_password_confirmation"))