Extract/improve auth response check - it's common to all mechanisms.
This commit is contained in:
parent
6ccf6e41a8
commit
5ab3a9be80
|
|
@ -146,23 +146,30 @@ func authenticatePlain(stream *Stream, user, password string) error {
|
||||||
if err := stream.Send(&auth); err != nil {
|
if err := stream.Send(&auth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return authenticateResponse(stream)
|
||||||
|
}
|
||||||
|
|
||||||
se, err := stream.Next(nil)
|
func authenticateResponse(stream *Stream) error {
|
||||||
if err != nil {
|
if se, err := stream.Next(nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
} else {
|
||||||
switch se.Name.Local {
|
switch se.Name.Local {
|
||||||
case "success":
|
case "success":
|
||||||
if err := stream.Skip(); err != nil {
|
if err := stream.Skip(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
case "failure":
|
case "failure":
|
||||||
f := new(saslFailure)
|
f := new(saslFailure)
|
||||||
stream.DecodeElement(f, se)
|
if err := stream.DecodeElement(f, se); err != nil {
|
||||||
return errors.New(fmt.Sprintf("Authentication failed: %s", f.Reason.Local))
|
return err
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("Authentication failed: %s", f.Reason.Local)
|
||||||
return nil
|
default:
|
||||||
|
return fmt.Errorf("Unexpected: %s", se.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
type saslAuth struct {
|
type saslAuth struct {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue