aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-01-10 19:35:55 +0100
committerSimon Ser <contact@emersion.fr>2020-01-10 19:37:24 +0100
commit425445f4430ebaacf6da23534eab969ed85b50d6 (patch)
treeb50bdee88742c61064bd9f9fe8a0ba77ae42fecd
parentc38b1d47f978bc36858b51b8da9159173eff69ff (diff)
downloadalps-425445f4430ebaacf6da23534eab969ed85b50d6.tar.gz
alps-425445f4430ebaacf6da23534eab969ed85b50d6.zip
Add Session.SetHTTPBasicAuth
This is not 100% idiot-proof, but still makes it mroe difficult for plugins to steal credentials.
-rw-r--r--session.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/session.go b/session.go
index e753d84..743cbf7 100644
--- a/session.go
+++ b/session.go
@@ -7,6 +7,7 @@ import (
"fmt"
"sync"
"time"
+ "net/http"
imapclient "github.com/emersion/go-imap/client"
"github.com/emersion/go-sasl"
@@ -104,6 +105,13 @@ func (s *Session) DoSMTP(f func(*smtp.Client) error) error {
return nil
}
+// SetHTTPBasicAuth adds an Authorization header field to the request with
+// this session's credentials.
+func (s *Session) SetHTTPBasicAuth(req *http.Request) {
+ // TODO: find a way to make it harder for plugins to steal credentials
+ req.SetBasicAuth(s.username, s.password)
+}
+
// Close destroys the session. This can be used to log the user out.
func (s *Session) Close() {
select {