Pular para o conteúdo
Cadastre-seEntrar

API de autenticação oauth

Troca do código de autorização e renovação do token do app. Abra uma rota para ver parâmetros, respostas e o exemplo de chamada.

Servidor da APIhttps://api.aquipede.com/public/v1
AutorizaçãoCabeçalho Authorization: Bearer, com a chave da loja ou o token do app
Baixar openapi.json
POST/oauth/tokenTroca o código

Troca o código (com o code_verifier do PKCE) ou o refresh pelo token de acesso do app. Público: autentica o código, o refresh e, no app confidencial, o client_secret (no corpo ou em Authorization: Basic).

Corpo da requisição (application/x-www-form-urlencoded)

CampoTipoObrigatórioDescrição
grant_typestring: authorization_code, refresh_tokenSim
client_idstringSim
client_secretstringNão
codestringNão
code_verifierstringNão
redirect_uristringNão
refresh_tokenstringNão

Exemplo

curl -sS -X POST "https://api.aquipede.com/public/v1/oauth/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code&code=CODIGO&code_verifier=VERIFICADOR&client_id=SEU_CLIENT_ID&redirect_uri=https%3A%2F%2Fseuapp.com.br%2Fretorno" \
  -w "\nstatus: %{http_code}\n"
const resposta = await fetch("https://api.aquipede.com/public/v1/oauth/token", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: new URLSearchParams("grant_type=authorization_code&code=CODIGO&code_verifier=VERIFICADOR&client_id=SEU_CLIENT_ID&redirect_uri=https%3A%2F%2Fseuapp.com.br%2Fretorno"),
});

const corpo = await resposta.json();
console.log(resposta.status, corpo);
const resposta = await fetch("https://api.aquipede.com/public/v1/oauth/token", {
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: new URLSearchParams("grant_type=authorization_code&code=CODIGO&code_verifier=VERIFICADOR&client_id=SEU_CLIENT_ID&redirect_uri=https%3A%2F%2Fseuapp.com.br%2Fretorno"),
});

const corpo = await resposta.json();
console.log(resposta.status, corpo);
import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart' as http;

Future<void> main() async {
  final resposta = await http.post(
    Uri.parse('https://api.aquipede.com/public/v1/oauth/token'),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    body: 'grant_type=authorization_code&code=CODIGO&code_verifier=VERIFICADOR&client_id=SEU_CLIENT_ID&redirect_uri=https%3A%2F%2Fseuapp.com.br%2Fretorno',
  );

  final corpo = jsonDecode(resposta.body) as Map<String, dynamic>;
  print('${resposta.statusCode} $corpo');
}
<?php

$ch = curl_init("https://api.aquipede.com/public/v1/oauth/token");
$cab = [
    'Content-Type: application/x-www-form-urlencoded',
];
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => $cab,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => 'grant_type=authorization_code&code=CODIGO&code_verifier=VERIFICADOR&client_id=SEU_CLIENT_ID&redirect_uri=https%3A%2F%2Fseuapp.com.br%2Fretorno',
]);
$resposta = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $status, ' ', json_encode($resposta), "\n";
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;

using var http = new HttpClient();
using var req = new HttpRequestMessage(HttpMethod.Post, "https://api.aquipede.com/public/v1/oauth/token");
req.Content = new StringContent("grant_type=authorization_code&code=CODIGO&code_verifier=VERIFICADOR&client_id=SEU_CLIENT_ID&redirect_uri=https%3A%2F%2Fseuapp.com.br%2Fretorno", Encoding.UTF8, "application/x-www-form-urlencoded");

using var resposta = await http.SendAsync(req);
var texto = await resposta.Content.ReadAsStringAsync();
Console.WriteLine((int)resposta.StatusCode + " " + texto);
/* gcc exemplo.c -lcurl */
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

static size_t guarda(char *p, size_t t, size_t n, void *dst) {
    fwrite(p, t, n, stdout); /* troque por um buffer para ler o JSON */
    return t * n;
}

int main(void) {
    CURL *h = curl_easy_init();
    struct curl_slist *cab = NULL;
    char linha[512];

    cab = curl_slist_append(cab, "Content-Type: application/x-www-form-urlencoded");

    curl_easy_setopt(h, CURLOPT_URL, "https://api.aquipede.com/public/v1/oauth/token");
    curl_easy_setopt(h, CURLOPT_CUSTOMREQUEST, "POST");
    curl_easy_setopt(h, CURLOPT_HTTPHEADER, cab);
    curl_easy_setopt(h, CURLOPT_POSTFIELDS, "grant_type=authorization_code&code=CODIGO&code_verifier=VERIFICADOR&client_id=SEU_CLIENT_ID&redirect_uri=https%3A%2F%2Fseuapp.com.br%2Fretorno");
    curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, guarda);

    CURLcode r = curl_easy_perform(h);
    long status = 0;
    curl_easy_getinfo(h, CURLINFO_RESPONSE_CODE, &status);
    printf("\nstatus: %ld\n", status);

    curl_slist_free_all(cab);
    curl_easy_cleanup(h);
    return r == CURLE_OK ? 0 : 1;
}
import os
import requests

resposta = requests.post(
    "https://api.aquipede.com/public/v1/oauth/token",
    headers={
        "Content-Type": "application/x-www-form-urlencoded",
    },
    data={
        "grant_type": "authorization_code",
        "code": "CODIGO",
        "code_verifier": "VERIFICADOR",
        "client_id": "SEU_CLIENT_ID",
        "redirect_uri": "https://seuapp.com.br/retorno",
    },
    timeout=10,
)
corpo = resposta.json()
print(resposta.status_code, corpo)

Respostas

Token emitido. O código ou o refresh token vale. A resposta é do formato OAuth, sem o envelope.

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Cache-Control: no-store

{
  "access_token": "exemplo",
  "token_type": "Bearer",
  "expires_in": 1,
  "refresh_token": "exemplo",
  "scope": "exemplo",
  "installation": 1
}

Pedido inválido. Falta parâmetro, código vencido ou usado, ou verificador que não confere.

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8

{
  "error": "invalid_grant",
  "error_description": "O código de autorização expirou ou já foi usado."
}

App não autenticado. client_id desconhecido ou app desativado.

HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8

{
  "error": "invalid_client",
  "error_description": "App desconhecido ou desativado."
}

Limite de uso. Muitas tentativas. Espere o Retry-After.

HTTP/1.1 429 Too Many Requests
Content-Type: application/json; charset=utf-8
Retry-After: 30

{
  "error": "rate_limited",
  "error_description": "Muitas tentativas. Tente de novo em 30 segundos."
}

Enter abre o primeiro resultado, Esc fecha

Autorizar chamadas de teste

Cole a chave da loja ou um token OAuth. Ela fica só nesta aba do navegador (sessionStorage): não vai para o servidor do developer, não entra em log e some quando você fecha a aba. As chamadas vão direto do seu navegador para api.aquipede.com.

Use a chave da loja de teste. Chave de loja real funciona igual, mas uma escrita muda dado de verdade.