mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Implement SSOLoginHelper
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
f8b0ef052f
commit
4b72b64a2e
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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});
|
||||||
|
25
src/matrix/login/SSOLoginHelper.js
Normal file
25
src/matrix/login/SSOLoginHelper.js
Normal 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}`;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user