mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-18 17:00:38 +01:00
Winni Neessen
5dbb1e6dde
This is a sync with the net/smtp upstream as committed here: 1d45a7ef56 (diff-4f6f6bdb9891d4dd271f9f31430420a2e44018fe4ee539576faf458bebb3cee4)
.
29 lines
888 B
Go
29 lines
888 B
Go
// SPDX-FileCopyrightText: Copyright (c) 2023 The go-mail Authors
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package smtp
|
|
|
|
type xoauth2Auth struct {
|
|
username, token string
|
|
}
|
|
|
|
// XOAuth2Auth returns an [Auth] that implements the XOAuth2 authentication
|
|
// mechanism as defined in the following specs:
|
|
//
|
|
// https://developers.google.com/gmail/imap/xoauth2-protocol
|
|
// https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth
|
|
func XOAuth2Auth(username, token string) Auth {
|
|
return &xoauth2Auth{username, token}
|
|
}
|
|
|
|
func (a *xoauth2Auth) Start(_ *ServerInfo) (string, []byte, error) {
|
|
return "XOAUTH2", []byte("user=" + a.username + "\x01" + "auth=Bearer " + a.token + "\x01\x01"), nil
|
|
}
|
|
|
|
func (a *xoauth2Auth) Next(_ []byte, more bool) ([]byte, error) {
|
|
if more {
|
|
return []byte(""), nil
|
|
}
|
|
return nil, nil
|
|
}
|