diff --git a/src/auth/FormElement.ts b/src/auth/FormElement.ts index edf073b6c301..7dd9990df8ba 100644 --- a/src/auth/FormElement.ts +++ b/src/auth/FormElement.ts @@ -53,11 +53,15 @@ export default class GmfAuthForm extends GmfBaseElement { @state() private allowPasswordReset = false; @state() private changingPassword = false; @state() private userMustChangeItsPassword = false; + @state() private openIdConnectUrl = ''; @state() private error = false; @state() private otpImage = ''; @state() private gmfUser: User = null; @state() private customCSS_ = ''; private changingPasswordUsername_ = ''; + private initialApplicationUrl = window.location.href; + private currentApplicationUrl = window.location.href; + private openIdConnectBaseUrl = ''; connectedCallback(): void { super.connectedCallback(); @@ -73,13 +77,21 @@ export default class GmfAuthForm extends GmfBaseElement { } }, }), + user.getLoginMessage().subscribe({ next: (message: string) => { this.loginInfoMessage = message; + this._updateOpenIdConnectUrl(); }, }), ); + window.addEventListener('popstate', () => { + this.currentApplicationUrl = window.location.href; + this._updateOpenIdConnectUrl(); + }); + this._updateOpenIdConnectUrl(); + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion const loginField = document.body.querySelector('input[slot=gmf-auth-login]') as HTMLInputElement; // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion @@ -97,11 +109,20 @@ export default class GmfAuthForm extends GmfBaseElement { }); } + _updateOpenIdConnectUrl(): void { + const applicationUrl = this.loginInfoMessage ? this.currentApplicationUrl : this.initialApplicationUrl; + const params = new URLSearchParams({ + came_from: applicationUrl, + }); + this.openIdConnectUrl = `${this.openIdConnectBaseUrl}?${params.toString()}`; + } + // override default initConfig initConfig(configuration: Configuration): void { this.twoFactorAuth = configuration.gmfTwoFactorAuth; this.allowPasswordChange = configuration.gmfAuthenticationConfig.allowPasswordChange; this.allowPasswordReset = configuration.gmfAuthenticationConfig.allowPasswordReset; + this.openIdConnectBaseUrl = configuration.gmfOidcLoginUrl; if (configuration.gmfCustomCSS && configuration.gmfCustomCSS.authentication !== undefined) { this.customCSS_ = configuration.gmfCustomCSS.authentication; } @@ -167,7 +188,7 @@ export default class GmfAuthForm extends GmfBaseElement {