Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Show client secret length on the interconnect form #1365 (#3256)

Abdullah13092fd850cd
diff --git a/ui/app/manager/src/pages/page-gateway.ts b/ui/app/manager/src/pages/page-gateway.ts
index 034bc5b4e..99111b4c7 100644
--- a/ui/app/manager/src/pages/page-gateway.ts
+++ b/ui/app/manager/src/pages/page-gateway.ts
@@ -45,6 +45,7 @@ import "@openremote/or-components/or-ace-editor";
import moment from "moment";
import type { OrAceEditor } from "@openremote/or-components/or-ace-editor";
import { showSnackbar } from "@openremote/or-mwc-components/or-mwc-snackbar";
+import { isAxiosError } from "@openremote/rest";
export function pageGatewayProvider(store: Store<AppStateKeyed>): PageProvider<AppStateKeyed> {
return {
@@ -397,11 +398,14 @@ export class PageGateway extends Page<AppStateKeyed> {
<or-vaadin-text-field
id="gateway-clientsecret"
required
+ minlength="36"
+ maxlength="36"
?disabled=${disabled}
value=${connection?.clientSecret}
@change=${(ev: Event) => this._setConnectionProperty("clientSecret", (ev.currentTarget as HTMLInputElement).value)}
>
<or-translate slot="label" value="clientSecret"></or-translate>
+ <or-translate slot="helper" value="gateway.clientSecretHelper"></or-translate>
</or-vaadin-text-field>
<or-vaadin-checkbox
id="gateway-secured"
@@ -687,17 +691,27 @@ export class PageGateway extends Page<AppStateKeyed> {
if (response.status === 204) {
this._loadData();
} else {
- showSnackbar(undefined, i18next.t("errorOccurred"));
+ this._showSaveError(response.status);
}
})
- .catch(() => {
- showSnackbar(undefined, i18next.t("errorOccurred"));
+ .catch((e) => {
+ this._showSaveError(isAxiosError(e) ? e.response?.status : undefined);
})
.finally(() => {
this._loading = false;
});
}
+ protected _showSaveError(status?: number) {
+ if (status === 401) {
+ showSnackbar(undefined, i18next.t("gateway.saveUnauthorized"));
+ } else if (status === 400) {
+ showSnackbar(undefined, i18next.t("gateway.saveInvalidInput"));
+ } else {
+ showSnackbar(undefined, i18next.t("errorOccurred"));
+ }
+ }
+
protected _setConnection(connection: GatewayConnection) {
this._connection = connection || { secured: true };
this._dirty = false;
@@ -748,6 +762,10 @@ export class PageGateway extends Page<AppStateKeyed> {
console.warn("Interconnect form can't be submitted: Client secret must be set.");
return false;
}
+ if (this._connection.clientSecret.length !== 36) {
+ console.warn("Interconnect form can't be submitted: Client secret must be 36 characters.");
+ return false;
+ }
return true;
}
diff --git a/ui/app/shared/locales/en/or.json b/ui/app/shared/locales/en/or.json
index 0be4b945e..b3631e6b1 100644
--- a/ui/app/shared/locales/en/or.json
+++ b/ui/app/shared/locales/en/or.json
@@ -435,7 +435,10 @@
"limit_sharing_rate": "Limit the rate of how often attribute value updates are shared",
"limit_sharing_rate_suffix": "minutes interval",
"assetSyncRulesEnable": "Customize asset synchronization",
- "assetSyncRulesInput": "Synchronization config"
+ "assetSyncRulesInput": "Synchronization config",
+ "clientSecretHelper": "Must be exactly 36 characters",
+ "saveUnauthorized": "Unauthorized",
+ "saveInvalidInput": "Please double check the inputs"
},
"gatewayTunnel": "Gateway tunnels",
"gatewayTunnels": {