From 82a22c89595703b757d3778c4c5d5ea8491b37c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Tue, 21 Feb 2023 14:12:21 +0100 Subject: [PATCH] Simplify outgoing Basic Authentication --- main.go | 3 +-- silence.go | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index cbcda6f..344830d 100644 --- a/main.go +++ b/main.go @@ -243,8 +243,7 @@ func (br *bridge) publish(n *notification) error { // ntfy authentication if br.cfg.ntfy.Password != "" && br.cfg.ntfy.User != "" { - auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", br.cfg.ntfy.User, br.cfg.ntfy.Password))) - req.Header.Set("Authorization", fmt.Sprintf("Basic %s", auth)) + req.SetBasicAuth(br.cfg.ntfy.User, br.cfg.ntfy.Password) } else if br.cfg.ntfy.AccessToken != "" { req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", br.cfg.ntfy.AccessToken)) } diff --git a/silence.go b/silence.go index 78d0951..b4cfc32 100644 --- a/silence.go +++ b/silence.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/base64" "encoding/json" - "fmt" "io" "net/http" "time" @@ -104,8 +103,7 @@ func (br *bridge) handleSilences(w http.ResponseWriter, r *http.Request) { // Basic auth if br.cfg.am.User != "" && br.cfg.am.Password != "" { - auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", br.cfg.am.User, br.cfg.am.Password))) - req.Header.Set("Authorization", fmt.Sprintf("Basic %s", auth)) + req.SetBasicAuth(br.cfg.am.User, br.cfg.am.Password) } req.Header.Add("Content-Type", "application/json")