Implement SSOLoginHelper

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-08-17 14:59:38 +05:30
parent f8b0ef052f
commit 4b72b64a2e
3 changed files with 29 additions and 3 deletions

View File

@ -54,7 +54,7 @@ export class SSOLoginViewModel extends ViewModel{
this._loadViewModel = this.track(new SessionLoadViewModel(this.childOptions({ this._loadViewModel = this.track(new SessionLoadViewModel(this.childOptions({
createAndStartSessionContainer: async () => { createAndStartSessionContainer: async () => {
if (loginOptions.sso) { if (loginOptions.sso) {
this._sessionContainer.startWithLogin(loginOptions.sso(this._loginToken)); this._sessionContainer.startWithLogin(loginOptions.token(this._loginToken));
} }
return this._sessionContainer; return this._sessionContainer;
}, },
@ -73,7 +73,7 @@ export class SSOLoginViewModel extends ViewModel{
async startSSOLogin() { async startSSOLogin() {
await this.platform.settingsStorage.setString("sso_ongoing_login_homeserver", this._homeserver); await this.platform.settingsStorage.setString("sso_ongoing_login_homeserver", this._homeserver);
const link = `${this._homeserver}/_matrix/client/r0/login/sso/redirect?redirectUrl=${this.urlCreator.createSSOCallbackURL()}`; const link = this._loginOptions.sso.ssoEndpointLink(this.urlCreator.createSSOCallbackURL());
this.platform.openUrl(link); this.platform.openUrl(link);
} }
} }

View File

@ -25,6 +25,7 @@ import {Sync, SyncStatus} from "./Sync.js";
import {Session} from "./Session.js"; import {Session} from "./Session.js";
import {PasswordLoginMethod} from "./login/PasswordLoginMethod.js"; import {PasswordLoginMethod} from "./login/PasswordLoginMethod.js";
import {TokenLoginMethod} from "./login/TokenLoginMethod.js"; import {TokenLoginMethod} from "./login/TokenLoginMethod.js";
import {SSOLoginHelper} from "./login/SSOLoginHelper.js";
export const LoadStatus = createEnum( export const LoadStatus = createEnum(
"NotLoading", "NotLoading",
@ -103,7 +104,7 @@ export class SessionContainer {
result.password = (username, password) => new PasswordLoginMethod({homeServer, username, password}); result.password = (username, password) => new PasswordLoginMethod({homeServer, username, password});
} }
else if (flow.type === "m.login.sso" && flows.find(flow => flow.type === "m.login.token")) { else if (flow.type === "m.login.sso" && flows.find(flow => flow.type === "m.login.token")) {
result.sso = loginToken => new TokenLoginMethod({homeServer, loginToken}); result.sso = new SSOLoginHelper(homeServer);
} }
else if (flow.type === "m.login.token") { else if (flow.type === "m.login.token") {
result.token = loginToken => new TokenLoginMethod({homeServer, loginToken}); result.token = loginToken => new TokenLoginMethod({homeServer, loginToken});

View File

@ -0,0 +1,25 @@
/*
Copyright 2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
export class SSOLoginHelper{
constructor(homeserver) {
this._homeserver = homeserver;
}
ssoEndpointLink(redirectURL) {
return `${this._homeserver}/_matrix/client/r0/login/sso/redirect?redirectUrl=${redirectURL}`;
}
}