mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-24 12:04:57 +01:00
Only generate the auth URL and start the login flow on click
This commit is contained in:
parent
9606de2e0f
commit
4b07f04843
@ -171,8 +171,8 @@ export class LoginViewModel extends ViewModel<SegmentType, Options> {
|
||||
this._startOIDCLoginViewModel = this.track(
|
||||
new StartOIDCLoginViewModel(this.childOptions({loginOptions: this._loginOptions}))
|
||||
);
|
||||
await this._startOIDCLoginViewModel.start();
|
||||
this.emitChange("startOIDCLoginViewModel");
|
||||
this._startOIDCLoginViewModel.discover();
|
||||
}
|
||||
|
||||
private _showError(message: string): void {
|
||||
@ -184,6 +184,7 @@ export class LoginViewModel extends ViewModel<SegmentType, Options> {
|
||||
this._isBusy = status;
|
||||
this._passwordLoginViewModel?.setBusy(status);
|
||||
this._startSSOLoginViewModel?.setBusy(status);
|
||||
this.startOIDCLoginViewModel?.setBusy(status);
|
||||
this.emitChange("isBusy");
|
||||
}
|
||||
|
||||
@ -301,7 +302,7 @@ export class LoginViewModel extends ViewModel<SegmentType, Options> {
|
||||
if (this._loginOptions) {
|
||||
if (this._loginOptions.sso) { this._showSSOLogin(); }
|
||||
if (this._loginOptions.password) { this._showPasswordLogin(); }
|
||||
if (this._loginOptions.oidc) { await this._showOIDCLogin(); }
|
||||
if (this._loginOptions.oidc) { this._showOIDCLogin(); }
|
||||
if (!this._loginOptions.sso && !this._loginOptions.password && !this._loginOptions.oidc) {
|
||||
this._showError("This homeserver supports neither SSO nor password based login flows");
|
||||
}
|
||||
|
@ -21,35 +21,39 @@ export class StartOIDCLoginViewModel extends ViewModel {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._isBusy = true;
|
||||
this._authorizationEndpoint = null;
|
||||
this._issuer = options.loginOptions.oidc.issuer;
|
||||
this._homeserver = options.loginOptions.homeserver;
|
||||
this._api = new OidcApi({
|
||||
clientId: "hydrogen-web",
|
||||
issuer: options.loginOptions.oidc.issuer,
|
||||
issuer: this._issuer,
|
||||
request: this.platform.request,
|
||||
encoding: this.platform.encoding,
|
||||
});
|
||||
this._homeserver = options.loginOptions.homeserver;
|
||||
}
|
||||
|
||||
get isBusy() { return this._isBusy; }
|
||||
get authorizationEndpoint() { return this._authorizationEndpoint; }
|
||||
|
||||
async start() {
|
||||
setBusy(status) {
|
||||
this._isBusy = status;
|
||||
this.emitChange("isBusy");
|
||||
}
|
||||
|
||||
async discover() {
|
||||
// Ask for the metadata once so it gets discovered and cached
|
||||
await this._api.metadata()
|
||||
}
|
||||
|
||||
async startOIDCLogin() {
|
||||
const p = this._api.generateParams("openid");
|
||||
await Promise.all([
|
||||
this.platform.settingsStorage.setInt(`oidc_${p.state}_started_at`, Date.now()),
|
||||
this.platform.settingsStorage.setString(`oidc_${p.state}_nonce`, p.nonce),
|
||||
this.platform.settingsStorage.setString(`oidc_${p.state}_code_verifier`, p.codeVerifier),
|
||||
this.platform.settingsStorage.setString(`oidc_${p.state}_homeserver`, this._homeserver),
|
||||
this.platform.settingsStorage.setString(`oidc_${p.state}_issuer`, this._api.issuer),
|
||||
this.platform.settingsStorage.setString(`oidc_${p.state}_issuer`, this._issuer),
|
||||
]);
|
||||
|
||||
this._authorizationEndpoint = await this._api.authorizationEndpoint(p);
|
||||
this._isBusy = false;
|
||||
}
|
||||
|
||||
setBusy(status) {
|
||||
this._isBusy = status;
|
||||
this.emitChange("isBusy");
|
||||
const link = await this._api.authorizationEndpoint(p);
|
||||
this.platform.openUrl(link);
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,9 @@ class StartOIDCLoginView extends TemplateView {
|
||||
return t.div({ className: "StartOIDCLoginView" },
|
||||
t.a({
|
||||
className: "StartOIDCLoginView_button button-action secondary",
|
||||
href: vm => (vm.isBusy ? "#" : vm.authorizationEndpoint),
|
||||
type: "button",
|
||||
onClick: () => vm.startOIDCLogin(),
|
||||
disabled: vm => vm.isBusy
|
||||
}, vm.i18n`Log in via OIDC`)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user