> ## Documentation Index
> Fetch the complete documentation index at: https://docs-finance.superpagamentos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Autenticar conta

> Gere um Bearer Token para autenticar as requisições à API

Gere o **Bearer Token de Cash In** a partir das suas credenciais e do certificado de Cash In. O token é usado no header `Authorization` das requisições de recebimento (API de QR Codes).

O token de Cash In expira em **300 segundos**. Renove-o antes desse prazo, contado a partir da última renovação.

<Warning>
  Os Bearer Tokens de Cash In e Cash Out são **separados**. O token gerado aqui vale apenas para as requisições de Cash In. Para transferências (Cash Out), gere um token próprio com o certificado e as credenciais de Cash Out.
</Warning>

## Certificados

Esta rota usa autenticação mútua (mTLS). Envie o certificado de **Cash In**, a chave e a senha na requisição:

<ParamField path="--cert" type="file" required>
  Certificado de Cash In do cliente (`client.crt`).
</ParamField>

<ParamField path="--key" type="file" required>
  Chave privada do cliente (`client.key`).
</ParamField>

<ParamField path="--pass" type="string" required>
  Senha para descriptografar a chave `.key`, enviada por e-mail junto com os certificados.
</ParamField>

## Headers

<ParamField header="Content-Type" type="string" required>
  Formato do corpo da requisição. Use `application/json`.
</ParamField>

## Body

<ParamField body="grant_type" type="string" required>
  Tipo de concessão OAuth. Use `client_credentials`.
</ParamField>

<ParamField body="client_id" type="string" required>
  Client ID gerado no painel FINANCE, em **Configurações → API QRCODES**.
</ParamField>

<ParamField body="client_secret" type="string" required>
  Client Secret gerado junto com o Client ID. Trate como segredo.
</ParamField>

## Resposta

<ResponseField name="access_token" type="string">
  Bearer Token usado no header `Authorization` das próximas requisições.
</ResponseField>

<ResponseField name="token_type" type="string">
  Tipo do token. Sempre `Bearer`.
</ResponseField>

<ResponseField name="expires_in" type="integer">
  Tempo de expiração do token, em segundos. `300` para Cash In.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.pix.basspago.com.br/oauth/token" \
    --cert ./client.crt \
    --key ./client.key \
    --pass "SUA_SENHA_DO_CERTIFICADO" \
    -H "Content-Type: application/json" \
    -d '{
      "grant_type": "client_credentials",
      "client_id": "SEU_CLIENT_ID",
      "client_secret": "SEU_CLIENT_SECRET"
    }'
  ```

  ```php PHP theme={null}
  <?php

  $ch = curl_init('https://api.pix.basspago.com.br/oauth/token');

  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_SSLCERT => './client.crt',
      CURLOPT_SSLKEY => './client.key',
      CURLOPT_KEYPASSWD => 'SUA_SENHA_DO_CERTIFICADO',
      CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
      CURLOPT_POSTFIELDS => json_encode([
          'grant_type' => 'client_credentials',
          'client_id' => 'SEU_CLIENT_ID',
          'client_secret' => 'SEU_CLIENT_SECRET',
      ]),
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ```

  ```javascript Node.js theme={null}
  import fs from "node:fs";
  import https from "node:https";
  import axios from "axios";

  const agent = new https.Agent({
    cert: fs.readFileSync("./client.crt"),
    key: fs.readFileSync("./client.key"),
    passphrase: "SUA_SENHA_DO_CERTIFICADO",
  });

  const { data } = await axios.post(
    "https://api.pix.basspago.com.br/oauth/token",
    {
      grant_type: "client_credentials",
      client_id: "SEU_CLIENT_ID",
      client_secret: "SEU_CLIENT_SECRET",
    },
    { httpsAgent: agent }
  );

  console.log(data);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - OK theme={null}
  {
    "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
    "token_type": "Bearer",
    "expires_in": 300
  }
  ```
</ResponseExample>
