Simplify outgoing Basic Authentication
This commit is contained in:
parent
d7fdd85b72
commit
82a22c8959
2 changed files with 2 additions and 5 deletions
3
main.go
3
main.go
|
@ -243,8 +243,7 @@ func (br *bridge) publish(n *notification) error {
|
||||||
|
|
||||||
// ntfy authentication
|
// ntfy authentication
|
||||||
if br.cfg.ntfy.Password != "" && br.cfg.ntfy.User != "" {
|
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.SetBasicAuth(br.cfg.ntfy.User, br.cfg.ntfy.Password)
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Basic %s", auth))
|
|
||||||
} else if br.cfg.ntfy.AccessToken != "" {
|
} else if br.cfg.ntfy.AccessToken != "" {
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", br.cfg.ntfy.AccessToken))
|
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", br.cfg.ntfy.AccessToken))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -104,8 +103,7 @@ func (br *bridge) handleSilences(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Basic auth
|
// Basic auth
|
||||||
if br.cfg.am.User != "" && br.cfg.am.Password != "" {
|
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.SetBasicAuth(br.cfg.am.User, br.cfg.am.Password)
|
||||||
req.Header.Set("Authorization", fmt.Sprintf("Basic %s", auth))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "application/json")
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
|
Loading…
Reference in a new issue