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

[24.2] Fix PSA Redirect #19247

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ async function submitOIDCLogin(idp: string) {
loading.value = true;

try {
const { data } = await axios.post(withPrefix(`/authnz/${idp}/login`));
const loginUrl = withPrefix(`/authnz/${idp}/login`);
const urlParams = new URLSearchParams(window.location.search);
const redirectParam = urlParams.get("redirect");

const formData = new FormData();
formData.append("next", redirectParam || "");

const { data } = await axios.post(loginUrl, formData, { withCredentials: true });

if (data.redirect_uri) {
window.location = data.redirect_uri;
Expand Down
10 changes: 7 additions & 3 deletions lib/galaxy/webapps/galaxy/controllers/authnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
log = logging.getLogger(__name__)

PROVIDER_COOKIE_NAME = "galaxy-oidc-provider"
LOGIN_NEXT_COOKIE_NAME = "galaxy-oidc-login-next"


class OIDC(JSAppLauncher):
Expand Down Expand Up @@ -72,12 +73,14 @@ def index(self, trans, **kwargs):

@web.json
@web.expose
def login(self, trans, provider, idphint=None):
def login(self, trans, provider, idphint=None, next=None):
if not trans.app.config.enable_oidc:
msg = "Login to Galaxy using third-party identities is not enabled on this Galaxy instance."
log.debug(msg)
return trans.show_error_message(msg)
success, message, redirect_uri = trans.app.authnz_manager.authenticate(provider, trans, idphint=idphint)
if next:
trans.set_cookie(value=next, name=LOGIN_NEXT_COOKIE_NAME)
success, message, redirect_uri = trans.app.authnz_manager.authenticate(provider, trans, idphint)
if success:
return {"redirect_uri": redirect_uri}
else:
Expand All @@ -86,6 +89,7 @@ def login(self, trans, provider, idphint=None):
@web.expose
def callback(self, trans, provider, idphint=None, **kwargs):
user = trans.user.username if trans.user is not None else "anonymous"
login_next = url_for(trans.get_cookie(name=LOGIN_NEXT_COOKIE_NAME) or "/")
if not bool(kwargs):
log.error(f"OIDC callback received no data for provider `{provider}` and user `{user}`")
return trans.show_error_message(
Expand All @@ -110,7 +114,7 @@ def callback(self, trans, provider, idphint=None, **kwargs):
kwargs.get("state", " "),
kwargs["code"],
trans,
login_redirect_url=url_for("/"),
login_redirect_url=login_next,
idphint=idphint,
)
except exceptions.AuthenticationFailed:
Expand Down
Loading