mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Implement SSO
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
474a4bb19a
commit
98f8f04c74
@ -15,6 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {ViewModel} from "../ViewModel.js";
|
import {ViewModel} from "../ViewModel.js";
|
||||||
|
import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
|
||||||
|
|
||||||
export class SSOLoginViewModel extends ViewModel{
|
export class SSOLoginViewModel extends ViewModel{
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -33,14 +34,46 @@ export class SSOLoginViewModel extends ViewModel{
|
|||||||
this._loadViewModelSubscription = null;
|
this._loadViewModelSubscription = null;
|
||||||
this._loadViewModel = null;
|
this._loadViewModel = null;
|
||||||
this._loginOptions = loginOptions;
|
this._loginOptions = loginOptions;
|
||||||
|
this.performSSOLoginCompletion();
|
||||||
}
|
}
|
||||||
|
|
||||||
get loadViewModel() { return this._loadViewModel; }
|
get loadViewModel() { return this._loadViewModel; }
|
||||||
get supportsSSOLogin() { return this._supportsSSOLogin; }
|
get supportsSSOLogin() { return this._supportsSSOLogin; }
|
||||||
get isSSOCompletion() { return !!this._loginToken; }
|
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() {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user