Autenticação
OAuth2 client_credentials
A API usa Bearer Token JWT emitido para o realm M2M ideabank-m2m via OAuth2 client_credentials. O acesso às contas é definido pelo vínculo integração ↔ conta no onboarding.
Endpoint de token
Troque suas credenciais por um access_token:
curl -X POST https://auth.ideabank.com.br/realms/ideabank-m2m/protocol/openid-connect/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=$CLIENT_ID" \
-d "client_secret=$CLIENT_SECRET"Usando o token
Em toda chamada, envie o header:
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIi...Ciclo de vida
- O token é curto (tipicamente ~5 min). Reaproveite-o em memória até faltar < 30s para expirar.
- Não há refresh token no fluxo M2M — solicite um novo
access_token. - Trate 401 como sinal para renovar o token e repetir a chamada.
Cliente HTTP recomendado (Node.js)
class IdeaCashClient {
#token?: { value: string; expiresAt: number };
constructor(private readonly cfg: {
baseUrl: string;
authUrl: string;
clientId: string;
clientSecret: string;
}) {}
async #getToken(): Promise<string> {
const now = Date.now();
if (this.#token && this.#token.expiresAt - 30_000 > now) {
return this.#token.value;
}
const res = await fetch(this.cfg.authUrl, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: this.cfg.clientId,
client_secret: this.cfg.clientSecret,
}),
});
if (!res.ok) throw new Error("auth_failed:" + res.status);
const json = await res.json();
this.#token = { value: json.access_token, expiresAt: now + json.expires_in * 1000 };
return this.#token.value;
}
async request<T>(path: string, init: RequestInit = {}): Promise<T> {
const token = await this.#getToken();
const res = await fetch(this.cfg.baseUrl + path, {
...init,
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
...(init.headers ?? {}),
},
});
if (res.status === 401) {
this.#token = undefined; // força renovação
}
if (!res.ok) throw Object.assign(new Error("http_" + res.status), { body: await res.text() });
return res.json() as Promise<T>;
}
}Boas práticas
Um único client HTTP com cache de token por processo. Log do header
X-Request-ID em toda requisição de saída — ele é a chave para o time de suporte investigar qualquer chamada.Detalhes de autorização por conta: Autorização por conta.
