From 98f8f04c74b2eb5b25a53bc70cec96fab1a67391 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Sun, 15 Aug 2021 16:36:03 +0530 Subject: [PATCH] Implement SSO Signed-off-by: RMidhunSuresh --- src/domain/login/SSOLoginViewModel.js | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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); } }