Repository: louislam/uptime-kuma
File: server/notification-providers/teltonika.js (JavaScript)

Code before:
            // Logging in, to get an access token.
            // API reference https://developers.teltonika-networks.com/reference/rut241/7.19.4/v1.11.1/authentication
            // Teltonika's API access tokens expire in 5 minutes, so we always get a new one.
            let loginData = {
                username: notification.teltonikaUsername,
                password: notification.teltonikaPassword,
            };

            let loginResp = await axios.post(loginUrl, loginData, axiosConfig);

            if (loginResp.data.success !== true) {
                throw Error("Login failed: " + loginResp.data.errors.error);
            }

            const teltonikaToken = "Bearer " + loginResp.data.data.token;

            // Sending the SMS.
            let smsData = {
                data: {
                    modem: notification.teltonikaModem,
                    number: notification.teltonikaPhoneNumber,
                    message: cleanMsg,
                },
            };

            axiosConfig.headers.Authorization = teltonikaToken;

            let smsResp = await axios.post(smsUrl, smsData, axiosConfig);

            if (smsResp.data.success !== true) {
                throw Error("Api returned: ", smsResp.data.errors.error);
            }

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Teltonika;


Review comment (security):
```suggestion
            // Sending the SMS.
            let smsData = {
                data: {
                    modem: notification.teltonikaModem,
                    number: notification.teltonikaPhoneNumber,
                    message: cleanMsg,
                },
            };

            axiosConfig.headers.Authorization = "Bearer " + loginResp.data.data.token;
```

Code after:
            // Logging in, to get an access token.
            // API reference https://developers.teltonika-networks.com/reference/rut241/7.19.4/v1.11.1/authentication
            // Teltonika's API access tokens expire in 5 minutes, so we always get a new one.
            let loginData = {
                username: notification.teltonikaUsername,
                password: notification.teltonikaPassword,
            };

            let loginResp = await axios.post(loginUrl, loginData, axiosConfig);

            if (loginResp.data.success !== true) {
                throw Error("Login failed: " + loginResp.data.errors.error);
            }

            // Sending the SMS.
            let smsData = {
                data: {
                    modem: notification.teltonikaModem,
                    number: notification.teltonikaPhoneNumber,
                    message: cleanMsg,
                },
            };

            axiosConfig.headers.Authorization = "Bearer " + loginResp.data.data.token;

            let smsResp = await axios.post(smsUrl, smsData, axiosConfig);

            if (smsResp.data.success !== true) {
                throw Error("Api returned: ", smsResp.data.errors.error);
            }

            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = Teltonika;