Referencia
Autenticación
OAuth2 client_credentials: un token opaco de una hora.
Pedir un token (client_credentials)
POST/v1/oauth/token
Sin token: se autentica con el client_secret.
OAuth2 client_credentials. El token es opaco, dura una hora y se revoca al instante al dar de baja al cliente.
Cuerpo application/x-www-form-urlencoded TokenRequest
grant_typestringobligatorioValores posibles:
client_credentialsclient_idstringobligatorioclient_secretstringobligatorioscopestringSeparados por espacios; subconjunto de los del cliente. Sin él, todos los del cliente.
Respuestas
- 200
Token emitido.
application/json
TokenResponse - 400
Petición mal formada o scope no permitido.
application/json
OAuthError - 401
Cliente o secreto incorrectos.
application/json
OAuthError
Petición · sandbox
curl -X POST https://sandbox.api.safeonuba.com/v1/oauth/token \
-d grant_type=client_credentials \
-d client_id="$SAFEONUBA_CLIENT_ID" \
-d client_secret="$SAFEONUBA_CLIENT_SECRET" \
-d scope="alerts:read musters:read"const res = await fetch('https://sandbox.api.safeonuba.com/v1/oauth/token', {
method: 'POST',
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: process.env.SAFEONUBA_CLIENT_ID,
client_secret: process.env.SAFEONUBA_CLIENT_SECRET,
scope: 'alerts:read musters:read',
}),
});
const { access_token, expires_in } = await res.json();import os
import requests
res = requests.post(
"https://sandbox.api.safeonuba.com/v1/oauth/token",
data={
"grant_type": "client_credentials",
"client_id": os.environ["SAFEONUBA_CLIENT_ID"],
"client_secret": os.environ["SAFEONUBA_CLIENT_SECRET"],
"scope": "alerts:read musters:read",
},
timeout=10,
)
res.raise_for_status()
token = res.json()["access_token"]using System.Net.Http.Json;
using System.Text.Json;
using var http = new HttpClient();
var res = await http.PostAsync("https://sandbox.api.safeonuba.com/v1/oauth/token", new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "client_credentials",
["client_id"] = Environment.GetEnvironmentVariable("SAFEONUBA_CLIENT_ID")!,
["client_secret"] = Environment.GetEnvironmentVariable("SAFEONUBA_CLIENT_SECRET")!,
["scope"] = "alerts:read musters:read",
}));
res.EnsureSuccessStatusCode();
var token = await res.Content.ReadFromJsonAsync<JsonElement>();Respuesta 200
{
"access_token": "at_9c1e…",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "alerts:read alerts:write musters:read"
}