Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

OIDC: extract success/failure handlers from token login function #11154

Merged
merged 10 commits into from
Jun 29, 2023

Conversation

kerryarchibald
Copy link
Contributor

@kerryarchibald kerryarchibald commented Jun 28, 2023

For element-hq/element-web#25657
Extracts success/failure handlers from Lifecycle.attemptTokenLogin function so they can be reused post OIDC authorization.

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

This change is marked as an internal change (Task), so will not be included in the changelog.

@kerryarchibald kerryarchibald added the T-Task Refactoring, enabling or disabling functionality, other engineering tasks label Jun 28, 2023
@kerryarchibald
Copy link
Contributor Author

Strict error is not related to these changes.

src/Lifecycle.ts Outdated Show resolved Hide resolved
src/Lifecycle.ts Outdated
title: _t("We couldn't log you in"),
description,
button: _t("Try again"),
onFinished: tryAgain,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we pass shouldTryAgain into the callback function? wouldn't it make more sense for this to be

Suggested change
onFinished: tryAgain,
onFinished: (shouldTryAgain) => { if (shouldTryAgain && !!tryAgain ) { tryAgain(); } },

or something to that effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dialog handles the case of a falsy onFinished

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following, I'm afraid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, now I think I see what you mean (if onFinished is falsey, it won't be called), but that's not really my point here.

My point is that I don't think it should be up to the tryAgain callback to check whether the user pressed "Try again" or "Cancel".

src/Lifecycle.ts Outdated
"We asked the browser to remember which homeserver you use to let you sign in, " +
"but unfortunately your browser has forgotten it. Go to the sign in page and try again.",
),
);
Modal.createDialog(ErrorDialog, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this dialog creation looks redundant now?

@robintown robintown removed their request for review June 28, 2023 17:18
Kerry Archibald and others added 2 commits June 29, 2023 08:44
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
src/Lifecycle.ts Outdated
Comment on lines 227 to 236
const tryAgainCallback: TryAgainFunction = (shouldTryAgain) => {
if (shouldTryAgain) {
const cli = createClient({
baseUrl: homeserver,
idBaseUrl: identityServer,
});
const idpId = localStorage.getItem(SSO_IDP_ID_KEY) || undefined;
PlatformPeg.get()?.startSingleSignOn(cli, "sso", fragmentAfterLogin, idpId, SSOAction.LOGIN);
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the other thread: I don't understand why the tryAgainCallback is called even if we don't actually want to try again.

Suggested change
const tryAgainCallback: TryAgainFunction = (shouldTryAgain) => {
if (shouldTryAgain) {
const cli = createClient({
baseUrl: homeserver,
idBaseUrl: identityServer,
});
const idpId = localStorage.getItem(SSO_IDP_ID_KEY) || undefined;
PlatformPeg.get()?.startSingleSignOn(cli, "sso", fragmentAfterLogin, idpId, SSOAction.LOGIN);
}
};
const tryAgainCallback: TryAgainFunction = () => {
const cli = createClient({
baseUrl: homeserver,
idBaseUrl: identityServer,
});
const idpId = localStorage.getItem(SSO_IDP_ID_KEY) || undefined;
PlatformPeg.get()?.startSingleSignOn(cli, "sso", fragmentAfterLogin, idpId, SSOAction.LOGIN);
};

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm on condition of pulling the if (shouldTryAgain) condition up to onFailedDelegatedAuthLogin

Merged via the queue into develop with commit 3930f1a Jun 29, 2023
20 checks passed
@kerryarchibald kerryarchibald deleted the kerry/25574/token-login-refactor branch June 29, 2023 22:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, enabling or disabling functionality, other engineering tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants