OIDC: add friendly errors (#11184)
* add delegatedauthentication to validated server config * dynamic client registration functions * test OP registration functions * add stubbed nativeOidc flow setup in Login * cover more error cases in Login * tidy * test dynamic client registration in Login * comment oidc_static_clients * register oidc inside Login.getFlows * strict fixes * remove unused code * and imports * comments * comments 2 * util functions to get static client id * check static client ids in login flow * remove dead code * OidcRegistrationClientMetadata type * navigate to oidc authorize url * exchange code for token * navigate to oidc authorize url * navigate to oidc authorize url * test * adjust for js-sdk code * login with oidc native flow: messy version * tidy * update test for response_mode query * tidy up some TODOs * use new types * add identityServerUrl to stored params * unit test completeOidcLogin * test tokenlogin * strict * whitespace * tidy * unit test oidc login flow in MatrixChat * strict * tidy * extract success/failure handlers from token login function * typo * use for no homeserver error dialog too * reuse post-token login functions, test * shuffle testing utils around * shuffle testing utils around * i18n * tidy * Update src/Lifecycle.ts Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> * tidy * comment * update tests for id token validation * move try again responsibility * prettier * add friendly error messages for oidc authorization failures * i18n * update for new translations, tidy --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
parent
eb7ce666b7
commit
1d9c24e96e
6 changed files with 84 additions and 11 deletions
|
@ -44,6 +44,7 @@ import {
|
|||
unmockClientPeg,
|
||||
} from "../../test-utils";
|
||||
import * as leaveRoomUtils from "../../../src/utils/leave-behaviour";
|
||||
import { OidcClientError } from "../../../src/utils/oidc/error";
|
||||
import * as voiceBroadcastUtils from "../../../src/voice-broadcast/utils/cleanUpBroadcasts";
|
||||
import LegacyCallHandler from "../../../src/LegacyCallHandler";
|
||||
import { CallStore } from "../../../src/stores/CallStore";
|
||||
|
@ -915,10 +916,13 @@ describe("<MatrixChat />", () => {
|
|||
|
||||
let loginClient!: ReturnType<typeof getMockClientWithEventEmitter>;
|
||||
|
||||
// for now when OIDC fails for any reason we just bump back to welcome
|
||||
// error handling screens in https://github.com/vector-im/element-web/issues/25665
|
||||
const expectOIDCError = async (): Promise<void> => {
|
||||
const expectOIDCError = async (
|
||||
errorMessage = "Something went wrong during authentication. Go to the sign in page and try again.",
|
||||
): Promise<void> => {
|
||||
await flushPromises();
|
||||
const dialog = await screen.findByRole("dialog");
|
||||
|
||||
expect(within(dialog).getByText(errorMessage)).toBeInTheDocument();
|
||||
// just check we're back on welcome page
|
||||
expect(document.querySelector(".mx_Welcome")!).toBeInTheDocument();
|
||||
};
|
||||
|
@ -972,7 +976,7 @@ describe("<MatrixChat />", () => {
|
|||
|
||||
expect(logger.error).toHaveBeenCalledWith(
|
||||
"Failed to login via OIDC",
|
||||
new Error("Invalid query parameters for OIDC native login. `code` and `state` are required."),
|
||||
new Error(OidcClientError.InvalidQueryParameters),
|
||||
);
|
||||
|
||||
await expectOIDCError();
|
||||
|
@ -1027,6 +1031,24 @@ describe("<MatrixChat />", () => {
|
|||
mocked(completeAuthorizationCodeGrant).mockRejectedValue(new Error(OidcError.CodeExchangeFailed));
|
||||
});
|
||||
|
||||
it("should log and return to welcome page with correct error when login state is not found", async () => {
|
||||
mocked(completeAuthorizationCodeGrant).mockRejectedValue(
|
||||
new Error(OidcError.MissingOrInvalidStoredState),
|
||||
);
|
||||
getComponent({ realQueryParams });
|
||||
|
||||
await flushPromises();
|
||||
|
||||
expect(logger.error).toHaveBeenCalledWith(
|
||||
"Failed to login via OIDC",
|
||||
new Error(OidcError.MissingOrInvalidStoredState),
|
||||
);
|
||||
|
||||
await expectOIDCError(
|
||||
"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.",
|
||||
);
|
||||
});
|
||||
|
||||
it("should log and return to welcome page", async () => {
|
||||
getComponent({ realQueryParams });
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue