curl --request POST \
--url https://api.historinhai.com.br/v1/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=algar-historinhai-a1b2c3 \
--data 'client_secret=<string>' \
--data scope=historinhai:engagement:readimport requests
url = "https://api.historinhai.com.br/v1/oauth2/token"
payload = {
"grant_type": "client_credentials",
"client_id": "algar-historinhai-a1b2c3",
"client_secret": "<string>",
"scope": "historinhai:engagement:read"
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: 'algar-historinhai-a1b2c3',
client_secret: '<string>',
scope: 'historinhai:engagement:read'
})
};
fetch('https://api.historinhai.com.br/v1/oauth2/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.historinhai.com.br/v1/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread",
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.historinhai.com.br/v1/oauth2/token"
payload := strings.NewReader("grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.historinhai.com.br/v1/oauth2/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.historinhai.com.br/v1/oauth2/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"token_type": "Bearer",
"expires_in": 600,
"scope": "historinhai:engagement:read"
}{
"error": "invalid_request",
"error_description": "Janela de período inválida"
}Troca client credentials por um token escopado ao HistorinhAI — planejado
Planejado — ainda não implementado. Hoje o HistorinhAI não emite token próprio: a única credencial de parceiro que ele reconhece é o token emitido pela Platform API (POST https://api.googa.com.br/v1/oauth2/token, ver Platform — OAuth2), verificado neste projeto com a chave pública do Platform. Este emissor próprio foi deliberadamente adiado para uma revisão dedicada, dado o que está em jogo no produto que trata dado de criança.
Quando existir: mesmo grant client_credentials do OAuth 2.0 (RFC 6749 §4.4) da Platform API, exposto sob o domínio próprio do HistorinhAI — defesa em profundidade, não duplicação acidental: a credencial emitida aqui só carregará escopos deste produto, com par de chaves próprio, de modo que comprometer uma credencial de NovelAI/NovelÁudio não dê acesso a este endpoint, e vice-versa.
O único escopo definido no desenho é historinhai:engagement:read — não há escopo de escrita, porque não há endpoint de escrita nesta API.
curl --request POST \
--url https://api.historinhai.com.br/v1/oauth2/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=algar-historinhai-a1b2c3 \
--data 'client_secret=<string>' \
--data scope=historinhai:engagement:readimport requests
url = "https://api.historinhai.com.br/v1/oauth2/token"
payload = {
"grant_type": "client_credentials",
"client_id": "algar-historinhai-a1b2c3",
"client_secret": "<string>",
"scope": "historinhai:engagement:read"
}
headers = {"Content-Type": "application/x-www-form-urlencoded"}
response = requests.post(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({
grant_type: 'client_credentials',
client_id: 'algar-historinhai-a1b2c3',
client_secret: '<string>',
scope: 'historinhai:engagement:read'
})
};
fetch('https://api.historinhai.com.br/v1/oauth2/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.historinhai.com.br/v1/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread",
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.historinhai.com.br/v1/oauth2/token"
payload := strings.NewReader("grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.historinhai.com.br/v1/oauth2/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.historinhai.com.br/v1/oauth2/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/x-www-form-urlencoded'
request.body = "grant_type=client_credentials&client_id=algar-historinhai-a1b2c3&client_secret=%3Cstring%3E&scope=historinhai%3Aengagement%3Aread"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"token_type": "Bearer",
"expires_in": 600,
"scope": "historinhai:engagement:read"
}{
"error": "invalid_request",
"error_description": "Janela de período inválida"
}