2023-05-29 18:19:01 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright (c) 2023 The go-mail Authors
|
2023-05-28 14:31:04 +02:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package smtp
|
|
|
|
|
|
|
|
type xoauth2Auth struct {
|
|
|
|
username, token string
|
|
|
|
}
|
|
|
|
|
2023-05-29 18:19:01 +02:00
|
|
|
func XOAuth2Auth(username, token string) Auth {
|
|
|
|
return &xoauth2Auth{username, token}
|
2023-05-28 14:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *xoauth2Auth) Start(_ *ServerInfo) (string, []byte, error) {
|
2023-05-29 18:19:01 +02:00
|
|
|
return "XOAUTH2", []byte("user=" + a.username + "\x01" + "auth=Bearer " + a.token + "\x01\x01"), nil
|
2023-05-28 14:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *xoauth2Auth) Next(_ []byte, more bool) ([]byte, error) {
|
|
|
|
if more {
|
2023-05-29 18:19:01 +02:00
|
|
|
return []byte(""), nil
|
2023-05-28 14:31:04 +02:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|