Guides

OAuth2

Refresh OAuth2 tokens and use them for SMTP XOAUTH2 authentication.

The one rule

Use a refresh token or getToken; do not embed a short-lived access token in application code.
import { OAuth2Client } from "sently/auth/oauth2";

const client = new OAuth2Client({
  user: "me@example.com", clientId: "...", clientSecret: "...", refreshToken: "...",
});
const token = await client.getAccessToken();

OAuth2Client caches tokens in memory and refreshes them before expiry.