File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments