Simplify outgoing Basic Authentication

This commit is contained in:
Thorben Günther 2023-02-21 14:12:21 +01:00
parent d7fdd85b72
commit 82a22c8959
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED
2 changed files with 2 additions and 5 deletions

View file

@ -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))
}

View file

@ -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")