Skip to content

Commit

Permalink
Merge pull request louislam#2905 from Sharknoon/ntfy-bearer-authoriza…
Browse files Browse the repository at this point in the history
…tion

Added option for notification provider ntfy to use access tokens
  • Loading branch information
louislam authored Apr 25, 2023
2 parents eb9c748 + a3e31b2 commit f75cf3a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
6 changes: 5 additions & 1 deletion server/notification-providers/ntfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ class Ntfy extends NotificationProvider {
let okMsg = "Sent Successfully.";
try {
let headers = {};
if (notification.ntfyusername) {
if (notification.ntfyAuthenticationMethod === "usernamePassword") {
headers = {
"Authorization": "Basic " + Buffer.from(notification.ntfyusername + ":" + notification.ntfypassword).toString("base64"),
};
} else if (notification.ntfyAuthenticationMethod === "accessToken") {
headers = {
"Authorization": "Bearer " + notification.ntfyaccesstoken,
};
}
// If heartbeatJSON is null, assume non monitoring notification (Certificate warning) or testing.
if (heartbeatJSON == null) {
Expand Down
36 changes: 33 additions & 3 deletions src/components/notifications/Ntfy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@
<input id="ntfy-priority" v-model="$parent.notification.ntfyPriority" type="number" class="form-control" required min="1" max="5" step="1">
</div>
<div class="mb-3">
<label for="ntfy-username" class="form-label">{{ $t("Username") }} ({{ $t("Optional") }})</label>
<label for="authentication-method" class="form-label">{{ $t("ntfyAuthenticationMethod") }}</label>
<select id="authentication-method" v-model="$parent.notification.ntfyAuthenticationMethod" class="form-select">
<option v-for="(name, type) in authenticationMethods" :key="type" :value="type">{{ name }}</option>
</select>
</div>
<div v-if="$parent.notification.ntfyAuthenticationMethod === 'usernamePassword'" class="mb-3">
<label for="ntfy-username" class="form-label">{{ $t("Username") }}</label>
<div class="input-group mb-3">
<input id="ntfy-username" v-model="$parent.notification.ntfyusername" type="text" class="form-control">
</div>
</div>
<div class="mb-3">
<label for="ntfy-password" class="form-label">{{ $t("Password") }} ({{ $t("Optional") }})</label>
<div v-if="$parent.notification.ntfyAuthenticationMethod === 'usernamePassword'" class="mb-3">
<label for="ntfy-password" class="form-label">{{ $t("Password") }}</label>
<div class="input-group mb-3">
<HiddenInput id="ntfy-password" v-model="$parent.notification.ntfypassword" autocomplete="new-password"></HiddenInput>
</div>
</div>
<div v-if="$parent.notification.ntfyAuthenticationMethod === 'accessToken'" class="mb-3">
<label for="ntfy-access-token" class="form-label">{{ $t("Access Token") }}</label>
<div class="input-group mb-3">
<HiddenInput id="ntfy-access-token" v-model="$parent.notification.ntfyaccesstoken"></HiddenInput>
</div>
</div>
<div class="mb-3">
<label for="ntfy-icon" class="form-label">{{ $t("IconUrl") }}</label>
<input id="ntfy-icon" v-model="$parent.notification.ntfyIcon" type="text" class="form-control">
Expand All @@ -40,11 +52,29 @@ export default {
components: {
HiddenInput,
},
computed: {
authenticationMethods() {
return {
none: this.$t("None"),
usernamePassword: this.$t("ntfyUsernameAndPassword"),
accessToken: this.$t("Access Token")
};
}
},
mounted() {
if (typeof this.$parent.notification.ntfyPriority === "undefined") {
this.$parent.notification.ntfyserverurl = "https://ntfy.sh";
this.$parent.notification.ntfyPriority = 5;
}
// Handling notifications that added before 1.22.0
if (typeof this.$parent.notification.ntfyAuthenticationMethod === "undefined") {
if (!this.$parent.notification.ntfyusername) {
this.$parent.notification.ntfyAuthenticationMethod = "none";
} else {
this.$parent.notification.ntfyAuthenticationMethod = "usernamePassword";
}
}
},
};
</script>
2 changes: 2 additions & 0 deletions src/lang/de-CH.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@
"lunaseaTarget": "Ziel",
"lunaseaDeviceID": "Geräte-ID",
"lunaseaUserID": "Benutzer-ID",
"ntfyAuthenticationMethod": "Authentifizierungsmethode",
"ntfyUsernameAndPassword": "Benutzername und Passwort",
"twilioAccountSID": "Account SID",
"twilioFromNumber": "Absender",
"twilioToNumber": "Empfänger",
Expand Down
2 changes: 2 additions & 0 deletions src/lang/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@
"lunaseaDeviceID": "Geräte-ID",
"lunaseaTarget": "Ziel",
"lunaseaUserID": "Benutzer-ID",
"ntfyAuthenticationMethod": "Authentifizierungsmethode",
"ntfyUsernameAndPassword": "Benutzername und Passwort",
"twilioAccountSID": "Account SID",
"twilioFromNumber": "Absender",
"twilioToNumber": "Empfänger",
Expand Down
2 changes: 2 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@
"lunaseaTarget": "Target",
"lunaseaDeviceID": "Device ID",
"lunaseaUserID": "User ID",
"ntfyAuthenticationMethod": "Authentication Method",
"ntfyUsernameAndPassword": "Username and Password",
"twilioAccountSID": "Account SID",
"twilioAuthToken": "Auth Token",
"twilioFromNumber": "From Number",
Expand Down

0 comments on commit f75cf3a

Please sign in to comment.