Exchange the authorization code from the OAuth redirect for tokens.
code query parameter from the redirect (valid for 5 minutes)
OptionalredirectUri?: stringRequired if the authorize URL included one; must match
// After the state check (see docs/guides/core/oauth.md)
if (typeof req.query.error === 'string') return res.redirect('/settings?connect=denied');
if (typeof req.query.code !== 'string') throw new Error('OAuth code missing');
const { accessToken, refreshToken, expiresAt, merchantId } =
await oauth.obtainToken({ code: req.query.code });
Get a new access token using a refresh token. Run this on a schedule
well before expiresAt — Square recommends every 7 days or less.
Revoke this application's access to a merchant. Pass the merchant's
merchantId to revoke every token issued to them, or an accessToken
to revoke that token (and its merchant's other tokens).
OptionalaccessToken?: undefinedOptionalrevokeOnlyAccessToken?: undefinedRevoke only accessToken, leaving
the refresh token and the authorization intact
OptionalmerchantId?: undefinedOptionalrevokeOnlyAccessToken?: booleanRevoke only accessToken, leaving
the refresh token and the authorization intact
OAuth client for the application-credential endpoints: exchanging an authorization code, refreshing, and revoking tokens.
These endpoints authenticate with the application's
clientId/clientSecret, not a merchant token — which is why this is separate from SquareClient. To check a merchant token's status, usecreateSquareClient({ accessToken }).oauth.tokenStatus().Example