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

# Autenticação com OAuth2 Client Credentials

> Obtenha um Bearer token com seu clientId e clientSecret para autenticar cada chamada à Identity Link API.

A Identity Link API usa OAuth2 com o fluxo `client_credentials`. Você envia seu `clientId` e `clientSecret` codificados em Base64 no cabeçalho `Authorization: Basic` e recebe um Bearer token válido por 3600 segundos. Todas as chamadas subsequentes devem incluir o token no cabeçalho `Authorization: Bearer`.

## Credenciais

Você pode consultar suas credenciais chamando `GET /users/me` com um token válido. A resposta inclui:

* `clientId`
* `clientSecret`
* `webhookSecret` (usado para validar assinaturas de webhook)

Guarde essas informações em variáveis de ambiente e nunca as exponha no frontend.

## Obter token

<CodeGroup>
  ```bash cURL theme={null}
  # Substitua CLIENT_ID e CLIENT_SECRET pelos seus valores reais
  BASE64=$(echo -n "CLIENT_ID:CLIENT_SECRET" | base64)

  curl -X POST https://api.identity.vu-one.com/api/v1/oauth/token \
    -H "Authorization: Basic $BASE64" \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -d "grant_type=client_credentials"
  ```

  ```javascript Node.js theme={null}
  const clientId = process.env.VU_CLIENT_ID;
  const clientSecret = process.env.VU_CLIENT_SECRET;

  const response = await fetch('https://api.identity.vu-one.com/api/v1/oauth/token', {
    method: 'POST',
    headers: {
      'Authorization': 'Basic ' + Buffer.from(`${clientId}:${clientSecret}`).toString('base64'),
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: 'grant_type=client_credentials',
  });

  const data = await response.json();
  console.log(data.access_token);
  ```

  ```python Python theme={null}
  import os, base64, requests

  client_id = os.environ['VU_CLIENT_ID']
  client_secret = os.environ['VU_CLIENT_SECRET']

  credentials = base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()

  response = requests.post(
      "https://api.identity.vu-one.com/api/v1/oauth/token",
      headers={
          "Authorization": f"Basic {credentials}",
          "Content-Type": "application/x-www-form-urlencoded",
      },
      data={"grant_type": "client_credentials"},
  )

  data = response.json()
  print(data["access_token"])
  ```
</CodeGroup>

### Resposta

```json theme={null}
{
  "access_token": "eyJhbGciOiJSUzI1NiIs...",
  "expires_in": 3600,
  "token_type": "Bearer"
}
```

## Usar o token

Inclua o token em todas as chamadas autenticadas:

```bash theme={null}
curl -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..." \
  https://api.identity.vu-one.com/api/v1/links
```

## Renovação e cache

<Tip>
  O token expira em 3600 segundos (1 hora). Armazene o token em cache e renove-o antes da expiração para evitar chamadas desnecessárias ao endpoint de token.
</Tip>

<Warning>
  Se o token estiver expirado ou inválido, a API retorna `401 Unauthorized`. Não tente reutilizar tokens de sessões anteriores sem verificar a validade.
</Warning>

A referência completa de códigos está em [Erros](/pt/identity-link/erros).


## Related topics

- [Identity Link API: Guia de Integração Completo](/pt/identity-link/introducao.md)
- [Changelog da Identity Link API](/pt/identity-link/changelog.md)
- [Documentação técnica da VU](/pt/index.md)
- [Códigos de Erro e Respostas da Identity Link API](/pt/identity-link/erros.md)
- [ID Analysis](/pt/vucs/id-analysis/introducao.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.