Improve error handling for OIDC discovery and registration

This commit is contained in:
Hugh Nimmo-Smith 2022-07-25 09:22:06 +01:00
parent 778900d0b2
commit 97bea400f6
2 changed files with 18 additions and 3 deletions

View File

@ -117,7 +117,12 @@ export class LoginViewModel extends ViewModel {
new StartOIDCLoginViewModel(this.childOptions({loginOptions: this._loginOptions})) new StartOIDCLoginViewModel(this.childOptions({loginOptions: this._loginOptions}))
); );
this.emitChange("startOIDCLoginViewModel"); this.emitChange("startOIDCLoginViewModel");
this._startOIDCLoginViewModel.discover(); try {
await this._startOIDCLoginViewModel.discover();
} catch (err) {
this._showError(err.message);
this._disposeViewModels();
}
} }
_showError(message) { _showError(message) {

View File

@ -41,8 +41,18 @@ export class StartOIDCLoginViewModel extends ViewModel {
async discover() { async discover() {
// Ask for the metadata once so it gets discovered and cached // Ask for the metadata once so it gets discovered and cached
try {
await this._api.metadata() await this._api.metadata()
} catch (err) {
this.logger.log("Failed to discover OIDC metadata: " + err);
throw new Error("Failed to discover OIDC metadata: " + err.message );
}
try {
await this._api.registration(); await this._api.registration();
} catch (err) {
this.logger.log("Failed to register OIDC client: " + err);
throw new Error("Failed to register OIDC client: " + err.message );
}
} }
async startOIDCLogin() { async startOIDCLogin() {