diff --git a/src/domain/login/SSOLoginViewModel.js b/src/domain/login/SSOLoginViewModel.js index 8bd9cd84..baa478f1 100644 --- a/src/domain/login/SSOLoginViewModel.js +++ b/src/domain/login/SSOLoginViewModel.js @@ -54,7 +54,7 @@ export class SSOLoginViewModel extends ViewModel{ this._loadViewModel = this.track(new SessionLoadViewModel(this.childOptions({ createAndStartSessionContainer: async () => { if (loginOptions.sso) { - this._sessionContainer.startWithLogin(loginOptions.sso(this._loginToken)); + this._sessionContainer.startWithLogin(loginOptions.token(this._loginToken)); } return this._sessionContainer; }, @@ -73,7 +73,7 @@ export class SSOLoginViewModel extends ViewModel{ async startSSOLogin() { 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); } } diff --git a/src/matrix/SessionContainer.js b/src/matrix/SessionContainer.js index 83696009..7492d0c3 100644 --- a/src/matrix/SessionContainer.js +++ b/src/matrix/SessionContainer.js @@ -25,6 +25,7 @@ import {Sync, SyncStatus} from "./Sync.js"; import {Session} from "./Session.js"; import {PasswordLoginMethod} from "./login/PasswordLoginMethod.js"; import {TokenLoginMethod} from "./login/TokenLoginMethod.js"; +import {SSOLoginHelper} from "./login/SSOLoginHelper.js"; export const LoadStatus = createEnum( "NotLoading", @@ -103,7 +104,7 @@ export class SessionContainer { result.password = (username, password) => new PasswordLoginMethod({homeServer, username, password}); } 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") { result.token = loginToken => new TokenLoginMethod({homeServer, loginToken}); diff --git a/src/matrix/login/SSOLoginHelper.js b/src/matrix/login/SSOLoginHelper.js new file mode 100644 index 00000000..701d00b4 --- /dev/null +++ b/src/matrix/login/SSOLoginHelper.js @@ -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}`; + } +}