> ## 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.

# Autenticación con OAuth2 client credentials

> Obtén un Bearer token con tus credenciales clientId y clientSecret para autenticar cada llamada a la Identity Link API.

La Identity Link API utiliza OAuth2 con el flujo client\_credentials. Todas las llamadas requieren un token Bearer que obtienes intercambiando tu `clientId` y `clientSecret`. Este token tiene una duración fija de 3600 segundos, tras lo cual debes solicitar uno nuevo.

## Dónde encontrar tus credenciales

Puedes consultar tus credenciales actuales llamando a `GET /users/me`. La respuesta incluye `clientId`, `clientSecret` y `webhookSecret`.

```bash theme={null}
curl -X GET https://api.identity.vu-one.com/api/v1/users/me \
  -H "Authorization: Bearer <tu_token_actual>"
```

## Obtener un token de acceso

Envía una petición `POST` a `/oauth/token` con las credenciales codificadas en Base64 en el header `Authorization: Basic`.

### Parámetros de la petición

| Parámetro | Ubicación | Valor |
| - | - | - |
| `Authorization` | Header | `Basic base64(clientId:clientSecret)` |
| `grant_type` | Body | `client_credentials` |

### Ejemplo con curl

<CodeGroup>
  ```bash curl theme={null}
  CLIENT_ID="tu_client_id"
  CLIENT_SECRET="tu_client_secret"
  BASIC_AUTH=$(echo -n "$CLIENT_ID:$CLIENT_SECRET" | base64)

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

  ```javascript JavaScript theme={null}
  const clientId = 'tu_client_id';
  const clientSecret = 'tu_client_secret';
  const basicAuth = btoa(`${clientId}:${clientSecret}`);

  const response = await fetch('https://api.identity.vu-one.com/api/v1/oauth/token', {
    method: 'POST',
    headers: {
      'Authorization': `Basic ${basicAuth}`,
      '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 base64
  import requests

  client_id = "tu_client_id"
  client_secret = "tu_client_secret"

  basic_auth = 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 {basic_auth}",
          "Content-Type": "application/x-www-form-urlencoded",
      },
      data={"grant_type": "client_credentials"},
  )

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

## Respuesta exitosa

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

## Usar el token en llamadas posteriores

Incluye el token en el header `Authorization` de todas las peticiones a la API:

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

## Errores comunes

| Código | Causa | Solución |
| - | - | - |
| `400` | `grant_type` ausente o inválido | Verifica que envías `grant_type=client_credentials` |
| `401` | Credenciales incorrectas o header `Authorization` mal formado | Revisa que codificaste `clientId:clientSecret` en Base64 |
| `401` | Token expirado | Solicita un nuevo token antes de reintentar |

El detalle completo de códigos está en [Errores](/identity-link/errores).

<Tip>
  Cachea el token en memoria y reutilízalo hasta que falten menos de 60 segundos para su expiración. Esto evita latencia innecesaria en cada llamada.
</Tip>

<Warning>
  Nunca expongas `clientSecret` en código frontend, repositorios públicos o logs. Almacénalo en variables de entorno o en un gestor de secretos.
</Warning>


## Related topics

- [Códigos de error y respuestas de la Identity Link API](/identity-link/errores.md)
- [Identity Link API: guía de integración completa](/identity-link/introduccion.md)
- [Documentación técnica de VU](/index.md)
- [Antispoofing Facial](/vucs/antispoofing-facial/introduccion.md)
- [ID Analysis](/vucs/id-analysis/introduccion.md)


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