Skip to content

Commit

Permalink
imapclient: add AUTHENTICATE example
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Aug 28, 2023
1 parent f750572 commit 38838c5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions imapclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"log"
"time"

"github.com/emersion/go-sasl"

"github.com/emersion/go-imap/v2"
"github.com/emersion/go-imap/v2/imapclient"
)
Expand Down Expand Up @@ -257,3 +259,23 @@ func ExampleClient_Idle() {
log.Fatalf("failed to stop idling: %v", err)
}
}

func ExampleClient_Authenticate_oauth() {
var (
c *imapclient.Client
username string
token string
)

if !c.Caps().Has(imap.AuthCap(sasl.OAuthBearer)) {
log.Fatal("OAUTHBEARER not supported by the server")
}

saslClient := sasl.NewOAuthBearerClient(&sasl.OAuthBearerOptions{
Username: username,
Token: token,
})
if err := c.Authenticate(saslClient); err != nil {
log.Fatalf("authentication failed: %v", err)
}
}

0 comments on commit 38838c5

Please sign in to comment.