Obter token de acesso
curl --request POST \
--url https://opendelivery.gohusky.net/logistic/oauth/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=123e4567-e89b-12d3-a456-426614174000 \
--data client_secret=sua-chave-secreta-aquiimport requests
url = "https://opendelivery.gohusky.net/logistic/oauth/token"
payload = {
"grant_type": "client_credentials",
"client_id": "123e4567-e89b-12d3-a456-426614174000",
"client_secret": "sua-chave-secreta-aqui"
}
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: '123e4567-e89b-12d3-a456-426614174000',
client_secret: 'sua-chave-secreta-aqui'
})
};
fetch('https://opendelivery.gohusky.net/logistic/oauth/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://opendelivery.gohusky.net/logistic/oauth/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=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui",
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://opendelivery.gohusky.net/logistic/oauth/token"
payload := strings.NewReader("grant_type=client_credentials&client_id=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui")
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://opendelivery.gohusky.net/logistic/oauth/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=client_credentials&client_id=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui")
.asString();require 'uri'
require 'net/http'
url = URI("https://opendelivery.gohusky.net/logistic/oauth/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=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui"
response = http.request(request)
puts response.read_body{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 604800
}{
"title": "Não autorizado",
"status": 401
}{
"title": "Serviço indisponível",
"status": 500
}Autenticação
Gerar Token
Obtém um token de acesso OAuth 2.0 usando o fluxo Client Credentials.
POST
/
oauth
/
token
Obter token de acesso
curl --request POST \
--url https://opendelivery.gohusky.net/logistic/oauth/token \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data grant_type=client_credentials \
--data client_id=123e4567-e89b-12d3-a456-426614174000 \
--data client_secret=sua-chave-secreta-aquiimport requests
url = "https://opendelivery.gohusky.net/logistic/oauth/token"
payload = {
"grant_type": "client_credentials",
"client_id": "123e4567-e89b-12d3-a456-426614174000",
"client_secret": "sua-chave-secreta-aqui"
}
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: '123e4567-e89b-12d3-a456-426614174000',
client_secret: 'sua-chave-secreta-aqui'
})
};
fetch('https://opendelivery.gohusky.net/logistic/oauth/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://opendelivery.gohusky.net/logistic/oauth/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=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui",
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://opendelivery.gohusky.net/logistic/oauth/token"
payload := strings.NewReader("grant_type=client_credentials&client_id=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui")
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://opendelivery.gohusky.net/logistic/oauth/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.body("grant_type=client_credentials&client_id=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui")
.asString();require 'uri'
require 'net/http'
url = URI("https://opendelivery.gohusky.net/logistic/oauth/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=123e4567-e89b-12d3-a456-426614174000&client_secret=sua-chave-secreta-aqui"
response = http.request(request)
puts response.read_body{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 604800
}{
"title": "Não autorizado",
"status": 401
}{
"title": "Serviço indisponível",
"status": 500
}Como autenticar
Siga os passos abaixo para obter e usar o token de acesso OAuth 2.0:1
Obter credenciais de cliente
Você precisa ter credenciais de cliente válidas (
client_id e client_secret) fornecidas pela Husky.Entre em contato com o suporte para obter suas credenciais se ainda não as possui.2
Fazer requisição POST para obter o token
Faça uma requisição POST para este endpoint. Ler Parâmetros esperados mais abaixo.
3
Receber o token de acesso
A resposta retornará um objeto JSON com o token de acesso. O token tem validade de 7 dias (604800 segundos).
A duração da validade pode ser alterada a qualquer momento, é preciso que sua integração esteja preparada para renovar token em caso de retorno como não autorizado.
4
Usar o token nas requisições
O token retornado deve ser usado no header Todos os endpoints protegidos requerem este token no header.
Authorization de todas as requisições subsequentes:Authorization: Bearer {access_token}
5
Renovar o token quando expirar
Quando o token expirar, você precisará obter um novo token usando este mesmo endpoint.
Se você receber um erro
401 Unauthorized, verifique se o token não expirou e obtenha um novo token.Body
application/x-www-form-urlencoded
Tipo de concessão OAuth. Deve ser sempre "client_credentials"
Available options:
client_credentials Example:
"client_credentials"
Identificador único do cliente
Example:
"123e4567-e89b-12d3-a456-426614174000"
Segredo do cliente
Example:
"sua-chave-secreta-aqui"
Response
Token de acesso obtido com sucesso
Token de acesso OAuth 2.0 que deve ser usado para autenticar requisições subsequentes
Example:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoi..."
Tipo do token, sempre "Bearer"
Available options:
Bearer Example:
"Bearer"
Tempo de expiração do token em segundos (7 dias = 604800 segundos)
Example:
604800
Was this page helpful?

