diff --git a/src/domain/login/SSOLoginViewModel.js b/src/domain/login/SSOLoginViewModel.js index 10691a37..d084727c 100644 --- a/src/domain/login/SSOLoginViewModel.js +++ b/src/domain/login/SSOLoginViewModel.js @@ -15,6 +15,7 @@ limitations under the License. */ import {ViewModel} from "../ViewModel.js"; +import {SessionLoadViewModel} from "../SessionLoadViewModel.js"; export class SSOLoginViewModel extends ViewModel{ constructor(options) { @@ -33,14 +34,46 @@ export class SSOLoginViewModel extends ViewModel{ this._loadViewModelSubscription = null; this._loadViewModel = null; this._loginOptions = loginOptions; + this.performSSOLoginCompletion(); } get loadViewModel() { return this._loadViewModel; } get supportsSSOLogin() { return this._supportsSSOLogin; } get isSSOCompletion() { return !!this._loginToken; } + async performSSOLoginCompletion() { + if (!this._loginToken) { + return; + } + const homeserver = await this.platform.settingsStorage.getString("homeserver"); + const loginOptions = await this._sessionContainer.queryLogin(homeserver); + this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription); + if (this._loadViewModel) { + this._loadViewModel = this.disposeTracked(this._loadViewModel); + } + this._loadViewModel = this.track(new SessionLoadViewModel(this.childOptions({ + createAndStartSessionContainer: async () => { + if (loginOptions.sso) { + this._sessionContainer.startWithLogin(loginOptions.sso(this._loginToken)); + } + return this._sessionContainer; + }, + ready: this._ready, + homeserver, + }))); + this._loadViewModel.start(); + this.emitChange("loadViewModel"); + this._loadViewModelSubscription = this.track(this._loadViewModel.disposableOn("change", () => { + if (!this._loadViewModel.loading) { + this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription); + } + this.emitChange("isBusy"); + })); + } async startSSOLogin() { - console.log("Next PR"); + await this.platform.settingsStorage.setString("homeserver", this._homeserver); + const link = `${this._homeserver}/_matrix/client/r0/login/sso/redirect?redirectUrl=${this.urlCreator.createSSOCallbackURL()}`; + this.platform.openUrl(link); } }