Get started
Authentication
DRUO uses the OAuth 2.0 client credentials flow.
Request a token from the token endpoint with your client credentials, then send it in the Authorization header of every API request.
http
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR...- Tokens expire after 86400 seconds (24 hours).
- Keep
client_secreton your server. Never ship it in a browser or mobile app. - Refresh the token shortly before it expires, or when you receive a 401 response.
Node.js token cache
let cached = { token: "", expiresAt: 0 };
export async function getDruoToken() {
if (Date.now() < cached.expiresAt - 60_000) return cached.token;
const res = await fetch("https://auth.druo.com/oauth/token", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
client_id: process.env.DRUO_CLIENT_ID,
client_secret: process.env.DRUO_CLIENT_SECRET,
audience: "https://druo-merchant-api.com",
grant_type: "client_credentials",
}),
});
const { access_token, expires_in } = await res.json();
cached = { token: access_token, expiresAt: Date.now() + Number(expires_in) * 1000 };
return access_token;
}
