Skip to content

Commit 500672a

Browse files
Merge pull request #21297 from uwwint/feature/oidc_error_handling
Update error message handling for OIDC
2 parents 989872d + 3477af1 commit 500672a

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

client/src/components/Login/LoginForm.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe("LoginForm", () => {
110110
const provider_label = "Provider";
111111

112112
const originalLocation = window.location;
113-
jest.spyOn(window, "location", "get").mockImplementation(() => ({
113+
const locationSpy = jest.spyOn(window, "location", "get").mockImplementation(() => ({
114114
...originalLocation,
115115
search: `?connect_external_email=${external_email}&connect_external_provider=${provider_id}&connect_external_label=${provider_label}`,
116116
}));
@@ -150,5 +150,21 @@ describe("LoginForm", () => {
150150
const postedURL = axiosMock.history.post?.[0]?.url;
151151
expect(postedURL).toBe("/user/login");
152152
await flushPromises();
153+
154+
locationSpy.mockRestore();
155+
});
156+
157+
it("renders message from query params", async () => {
158+
const originalUrl = window.location.href;
159+
window.history.replaceState(null, "", "/login/start?message=auth-error&status=info");
160+
161+
const wrapper = await mountLoginForm();
162+
163+
const alert = wrapper.find(".alert");
164+
expect(alert.exists()).toBe(true);
165+
expect(alert.text()).toContain("auth-error");
166+
expect(alert.classes()).toContain("alert-info");
167+
168+
window.history.replaceState(null, "", originalUrl);
153169
});
154170
});

client/src/components/Login/LoginForm.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ const login = ref("");
5555
const password = ref(null);
5656
const passwordState = ref<boolean | null>(null);
5757
const loading = ref(false);
58-
const messageText = ref("");
59-
const messageVariant = ref<"info" | "danger">("info");
58+
const networkMessage = urlParams.get("message") || "";
59+
const messageText = ref(networkMessage);
60+
const statusParam = urlParams.get("status");
61+
const messageVariant = ref<"info" | "danger">(statusParam === "info" ? "info" : "danger");
6062
const connectExternalEmail = ref(urlParams.get("connect_external_email"));
6163
const connectExternalLabel = ref(urlParams.get("connect_external_label"));
6264
const connectExternalProvider = ref(urlParams.get("connect_external_provider"));

lib/galaxy/webapps/galaxy/controllers/authnz.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,17 @@ def callback(self, trans, provider, idphint=None, **kwargs):
116116
"Error handling authentication callback from `{}` identity provider for user `{}` login request."
117117
" Error message: {}".format(provider, user, kwargs.get("error", "None"))
118118
)
119-
return trans.show_error_message(
120-
f"Failed to handle authentication callback from {provider}. "
121-
"Please try again, and if the problem persists, contact "
122-
"the Galaxy instance admin"
123-
)
119+
error_description = kwargs.get("error_description")
120+
if error_description:
121+
error_msg = error_description
122+
else:
123+
error_msg = (
124+
f"Failed to handle authentication callback from {provider}. "
125+
"Please try again, and if the problem persists, contact "
126+
"the Galaxy instance admin."
127+
)
128+
redirect_to = trans.url_builder("/login/start", message=error_msg, status="danger")
129+
return trans.response.send_redirect(redirect_to)
124130
try:
125131
success, message, (redirect_url, user) = trans.app.authnz_manager.callback(
126132
provider,

0 commit comments

Comments
 (0)