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

add auth type to param to cp auth #133

Merged
merged 2 commits into from
Oct 3, 2023
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
22 changes: 17 additions & 5 deletions server/cp/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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"))

Expand Down Expand Up @@ -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"))

Expand Down
Loading