Skip to content

Commit 38838c5

Browse files
committed
imapclient: add AUTHENTICATE example
1 parent f750572 commit 38838c5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

imapclient/client_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"log"
66
"time"
77

8+
"github.com/emersion/go-sasl"
9+
810
"github.com/emersion/go-imap/v2"
911
"github.com/emersion/go-imap/v2/imapclient"
1012
)
@@ -257,3 +259,23 @@ func ExampleClient_Idle() {
257259
log.Fatalf("failed to stop idling: %v", err)
258260
}
259261
}
262+
263+
func ExampleClient_Authenticate_oauth() {
264+
var (
265+
c *imapclient.Client
266+
username string
267+
token string
268+
)
269+
270+
if !c.Caps().Has(imap.AuthCap(sasl.OAuthBearer)) {
271+
log.Fatal("OAUTHBEARER not supported by the server")
272+
}
273+
274+
saslClient := sasl.NewOAuthBearerClient(&sasl.OAuthBearerOptions{
275+
Username: username,
276+
Token: token,
277+
})
278+
if err := c.Authenticate(saslClient); err != nil {
279+
log.Fatalf("authentication failed: %v", err)
280+
}
281+
}

0 commit comments

Comments
 (0)