added LOGIN auth scheme to satellite mail service (#1552)
This commit is contained in:
parent
b9bb986b8a
commit
cce6fa8fd3
40
internal/post/login.go
Normal file
40
internal/post/login.go
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright (C) 2019 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package post
|
||||
|
||||
import (
|
||||
"net/smtp"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
)
|
||||
|
||||
// LoginAuth implements LOGIN authentication mechanism
|
||||
type LoginAuth struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
// Start begins an authentication with a server
|
||||
func (auth LoginAuth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error) {
|
||||
if !server.TLS {
|
||||
return "", nil, errs.New("unencrypted connection")
|
||||
}
|
||||
return "LOGIN", nil, nil
|
||||
}
|
||||
|
||||
// Next continues the authentication with server response and flag representing
|
||||
// if server expects more data from client
|
||||
func (auth LoginAuth) Next(fromServer []byte, more bool) (toServer []byte, err error) {
|
||||
if more {
|
||||
switch string(fromServer) {
|
||||
case "Username:":
|
||||
return []byte(auth.Username), nil
|
||||
case "Password:":
|
||||
return []byte(auth.Password), nil
|
||||
default:
|
||||
return nil, errs.New("unknown question")
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
@ -25,6 +25,10 @@ type Auth struct {
|
||||
|
||||
// Start returns proto and auth credentials for first auth msg
|
||||
func (auth *Auth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error) {
|
||||
if !server.TLS {
|
||||
return "", nil, errs.New("unencrypted connection")
|
||||
}
|
||||
|
||||
token, err := auth.Storage.Token()
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
|
@ -448,8 +448,8 @@ func (planet *Planet) newSatellites(count int) ([]*satellite.Peer, error) {
|
||||
Interval: 120 * time.Second,
|
||||
},
|
||||
Mail: mailservice.Config{
|
||||
SMTPServerAddress: "smtp.gmail.com:587",
|
||||
From: "Labs <yaroslav-satellite-test@storj.io>",
|
||||
SMTPServerAddress: "smtp.mail.example.com:587",
|
||||
From: "Labs <storj@example.com>",
|
||||
AuthType: "simulate",
|
||||
},
|
||||
Console: consoleweb.Config{
|
||||
|
@ -21,8 +21,8 @@ type Config struct {
|
||||
TemplatePath string `help:"path to email templates source" default:""`
|
||||
From string `help:"sender email address" default:""`
|
||||
AuthType string `help:"smtp authentication type" default:"simulate"`
|
||||
PlainLogin string `help:"plain auth user login" default:""`
|
||||
PlainPassword string `help:"plain auth user password" default:""`
|
||||
Login string `help:"plain/login auth user login" default:""`
|
||||
Password string `help:"plain/login auth user password" default:""`
|
||||
RefreshToken string `help:"refresh token used to retrieve new access token" default:""`
|
||||
ClientID string `help:"oauth2 app's client id" default:""`
|
||||
ClientSecret string `help:"oauth2 app's client secret" default:""`
|
||||
|
@ -421,7 +421,16 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, config *Config) (*
|
||||
case "plain":
|
||||
sender = &post.SMTPSender{
|
||||
From: *from,
|
||||
Auth: smtp.PlainAuth("", mailConfig.PlainLogin, mailConfig.PlainPassword, host),
|
||||
Auth: smtp.PlainAuth("", mailConfig.Login, mailConfig.Password, host),
|
||||
ServerAddress: mailConfig.SMTPServerAddress,
|
||||
}
|
||||
case "login":
|
||||
sender = &post.SMTPSender{
|
||||
From: *from,
|
||||
Auth: post.LoginAuth{
|
||||
Username: mailConfig.Login,
|
||||
Password: mailConfig.Password,
|
||||
},
|
||||
ServerAddress: mailConfig.SMTPServerAddress,
|
||||
}
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user