OAuth
Autoryzacja aplikacji: Authorization Code + PKCE (S256), odświeżanie z rotacją, token aplikacji (client_credentials), odwołanie (RFC 7009). Zgodne z Allegro.
Autoryzacja: przekierowanie sprzedawcy
GET /auth/oauth/authorize
zgodna z Allegro
Adres, na który aplikacja kieruje przeglądarkę sprzedawcy (Authorization Code + PKCE, tylko S256). Poprawne żądanie → 302 na stronę zgody allee.pl; sprzedawca loguje się i klika „Zezwól” → 302 na redirect_uri?code=…&state=….
redirect_uriporównujemy 1:1 z zarejestrowanym (bajt w bajt).- Zły
client_id, nieaktywna aplikacja albo obcyredirect_uri→ strona błędu 400 bez przekierowania (ochrona przed otwartym przekierowaniem). - Błąd po potwierdzeniu
redirect_uri→ 302redirect_uri?error=invalid_request|invalid_scope|unsupported_response_type&state=…. - Zakresy: nazwy Allegro (
allegro:api:…) albo allee (allee:api:…); nieznane są pomijane.
Zgodność: zgodna z Allegro REST API (ten sam kształt) — GET https://allegro.pl/auth/oauth/authorize.
Uwierzytelnienie: brak.
Parametry zapytania
response_type string wymaganyZawsze code.
codeclient_id string wymaganyclient_id aplikacji.
redirect_uri string · uri wymaganyZarejestrowany adres powrotu.
state stringWartość ochronna (CSRF) — wraca bez zmian.
code_challenge string wymaganyBASE64URL(SHA256(code_verifier)).
code_challenge_method string wymaganyTylko S256.
S256scope stringZakresy rozdzielone spacją.
Odpowiedzi
302 Przekierowanie na stronę zgody (albo na redirect_uri z błędem).
Błędy
| HTTP | Kod | Znaczenie |
|---|---|---|
| 500 | INTERNAL_ERROR | Błąd serwera allee. |
curl -sS -X GET "${ALLEE_API_URL:-https://api.allee.pl}/auth/oauth/authorize?response_type=code&client_id=36d6ed33acd3fc480a9270abe6421e9c&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&state=st-7f3a9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&scope=allegro%3Aapi%3Aprofile%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Awrite" \
-H "Accept: text/html" \
-w '\nHTTP %{http_code}\n'<?php
// allee API: GET /auth/oauth/authorize (PHP 8, rozszerzenie curl)
$base = getenv('ALLEE_API_URL') ?: 'https://api.allee.pl';
$ch = curl_init($base . '/auth/oauth/authorize?response_type=code&client_id=36d6ed33acd3fc480a9270abe6421e9c&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&state=st-7f3a9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&scope=allegro%3Aapi%3Aprofile%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Awrite');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'Accept: text/html',
],
CURLOPT_RETURNTRANSFER => true,
]);
$odp = curl_exec($ch);
echo 'HTTP ', curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $odp, "\n";# allee API: GET /auth/oauth/authorize (Python 3, biblioteka requests)
import os
import requests
BASE = os.environ.get("ALLEE_API_URL", "https://api.allee.pl")
headers = {
"Accept": "text/html",
}
r = requests.request("GET", BASE + "/auth/oauth/authorize?response_type=code&client_id=36d6ed33acd3fc480a9270abe6421e9c&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&state=st-7f3a9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&scope=allegro%3Aapi%3Aprofile%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Awrite", headers=headers, timeout=60, allow_redirects=False)
print("HTTP", r.status_code)
print(r.text)// allee API: GET /auth/oauth/authorize (Node.js 18+, wbudowany fetch; plik .mjs)
const BASE = process.env.ALLEE_API_URL ?? "https://api.allee.pl";
const res = await fetch(`${BASE}/auth/oauth/authorize?response_type=code&client_id=36d6ed33acd3fc480a9270abe6421e9c&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&state=st-7f3a9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&scope=allegro%3Aapi%3Aprofile%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Awrite`, {
method: "GET",
headers: {
"Accept": "text/html",
},
redirect: "manual",
});
console.log("HTTP", res.status);
console.log(await res.text());// allee API: GET /auth/oauth/authorize (C#, .NET 8+, HttpClient)
using System.Net.Http.Headers;
using System.Text;
var baseUrl = Environment.GetEnvironmentVariable("ALLEE_API_URL") ?? "https://api.allee.pl";
using var http = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
using var req = new HttpRequestMessage(new HttpMethod("GET"), baseUrl + "/auth/oauth/authorize?response_type=code&client_id=36d6ed33acd3fc480a9270abe6421e9c&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&state=st-7f3a9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&scope=allegro%3Aapi%3Aprofile%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Awrite");
req.Headers.Accept.ParseAdd("text/html");
using var res = await http.SendAsync(req);
Console.WriteLine($"HTTP {(int)res.StatusCode}");
Console.WriteLine(await res.Content.ReadAsStringAsync());// allee API: GET /auth/oauth/authorize (Java 11+, java.net.http; uruchom: java Main.java)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String base = System.getenv().getOrDefault("ALLEE_API_URL", "https://api.allee.pl");
HttpRequest req = HttpRequest.newBuilder(URI.create(base + "/auth/oauth/authorize?response_type=code&client_id=36d6ed33acd3fc480a9270abe6421e9c&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&state=st-7f3a9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&scope=allegro%3Aapi%3Aprofile%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Awrite"))
.header("Accept", "text/html")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpClient http = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println("HTTP " + res.statusCode());
System.out.println(res.body());
}
}// allee API: GET /auth/oauth/authorize (Go 1.20+, net/http; uruchom: go run main.go)
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
base := os.Getenv("ALLEE_API_URL")
if base == "" {
base = "https://api.allee.pl"
}
req, err := http.NewRequest("GET", base+"/auth/oauth/authorize?response_type=code&client_id=36d6ed33acd3fc480a9270abe6421e9c&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&state=st-7f3a9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&scope=allegro%3Aapi%3Aprofile%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Aread%20allegro%3Aapi%3Asale%3Aoffers%3Awrite", nil)
if err != nil {
panic(err)
}
req.Header.Set("Accept", "text/html")
// nie podążamy za przekierowaniami (authorize odpowiada 302)
klient := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
res, err := klient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
dane, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println("HTTP", res.StatusCode)
fmt.Println(string(dane))
}text/html; charset=UTF-8(0 B: text/html; charset=UTF-8)Token: kod, odświeżenie, token aplikacji
POST /auth/oauth/token
Allegro + rozszerzenia
Wywołanie serwer–serwer. Uwierzytelnienie klienta: Authorization: Basic base64(client_id:client_secret). Ciało application/x-www-form-urlencoded.
| grant_type | pola | wynik |
|---|---|---|
authorization_code | code, redirect_uri, code_verifier | para tokenów (access 12 h, refresh 90 dni) |
refresh_token | refresh_token, opcjonalnie scope (zawężenie) | nowa para — stary refresh przestaje działać (rotacja; ponowne użycie poza 60-sekundowym oknem łaski odwołuje całą rodzinę tokenów) |
client_credentials | — | token aplikacji bez sprzedawcy: tylko dane publiczne (kategorie, parametry, metody dostawy, przewoźnicy) |
Kod autoryzacyjny jest jednorazowy (10 min) — nieudana wymiana też go zużywa. Odświeżaj pojedynczo i zapisuj nową parę atomowo. Błędy w formacie OAuth (error, error_description).
Zgodność: zgodna z Allegro REST API, z rozszerzeniami allee (pola allee.*, alleeId) — POST https://allegro.pl/auth/oauth/token.
Uwierzytelnienie: klient OAuth — Authorization: Basic base64(client_id:client_secret).
Treść żądania application/x-www-form-urlencoded
grant_type string wymaganeauthorization_code, refresh_token, client_credentialscode stringredirect_uri stringcode_verifier string43–128 znaków.
refresh_token stringscope stringZawężenie zakresów przy odświeżaniu.
Odpowiedzi
200 Tokeny. · TokenResponse
access_token string zawszeToken dostępu (12 h). Nowe aplikacje: allee_at_…
token_type string zawszebearerrefresh_token stringRefresh token (90 dni, rotacja przy każdym użyciu). Brak przy client_credentials.
expires_in integer zawszeWażność access tokenu w sekundach (43200).
scope string zawszePrzyznane zakresy rozdzielone spacją — zapisz je.
jti stringallee objectBłędy
| HTTP | Kod | Znaczenie |
|---|---|---|
| 500 | INTERNAL_ERROR | Błąd serwera allee. |
curl -sS -X POST "${ALLEE_API_URL:-https://api.allee.pl}/auth/oauth/token" \
-u "$ALLEE_CLIENT_ID:$ALLEE_CLIENT_SECRET" \
-H "Accept: application/json" \
--data-urlencode "grant_type=authorization_code" \
--data-urlencode "code={kod_z_przekierowania}" \
--data-urlencode "redirect_uri=https://integrator.example.com/allee/powrot" \
--data-urlencode "code_verifier={code_verifier}" \
-w '\nHTTP %{http_code}\n'<?php
// allee API: POST /auth/oauth/token (PHP 8, rozszerzenie curl)
$base = getenv('ALLEE_API_URL') ?: 'https://api.allee.pl';
$ch = curl_init($base . '/auth/oauth/token');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Accept: application/json',
],
CURLOPT_USERPWD => getenv('ALLEE_CLIENT_ID') . ':' . getenv('ALLEE_CLIENT_SECRET'),
CURLOPT_POSTFIELDS => http_build_query([
'grant_type' => 'authorization_code',
'code' => '{kod_z_przekierowania}',
'redirect_uri' => 'https://integrator.example.com/allee/powrot',
'code_verifier' => '{code_verifier}',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$odp = curl_exec($ch);
echo 'HTTP ', curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $odp, "\n";# allee API: POST /auth/oauth/token (Python 3, biblioteka requests)
import os
import requests
BASE = os.environ.get("ALLEE_API_URL", "https://api.allee.pl")
headers = {
"Accept": "application/json",
}
form = {
"grant_type": "authorization_code",
"code": "{kod_z_przekierowania}",
"redirect_uri": "https://integrator.example.com/allee/powrot",
"code_verifier": "{code_verifier}",
}
r = requests.request("POST", BASE + "/auth/oauth/token", headers=headers, data=form, auth=(os.environ["ALLEE_CLIENT_ID"], os.environ["ALLEE_CLIENT_SECRET"]), timeout=60, allow_redirects=False)
print("HTTP", r.status_code)
print(r.text)// allee API: POST /auth/oauth/token (Node.js 18+, wbudowany fetch; plik .mjs)
const BASE = process.env.ALLEE_API_URL ?? "https://api.allee.pl";
const form = new URLSearchParams({
"grant_type": "authorization_code",
"code": "{kod_z_przekierowania}",
"redirect_uri": "https://integrator.example.com/allee/powrot",
"code_verifier": "{code_verifier}"
});
const res = await fetch(`${BASE}/auth/oauth/token`, {
method: "POST",
headers: {
Authorization: "Basic " + Buffer.from(`${process.env.ALLEE_CLIENT_ID}:${process.env.ALLEE_CLIENT_SECRET}`).toString("base64"),
"Accept": "application/json",
},
body: form,
redirect: "manual",
});
console.log("HTTP", res.status);
console.log(await res.text());// allee API: POST /auth/oauth/token (C#, .NET 8+, HttpClient)
using System.Net.Http.Headers;
using System.Text;
var baseUrl = Environment.GetEnvironmentVariable("ALLEE_API_URL") ?? "https://api.allee.pl";
using var http = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
using var req = new HttpRequestMessage(new HttpMethod("POST"), baseUrl + "/auth/oauth/token");
var klient = Environment.GetEnvironmentVariable("ALLEE_CLIENT_ID") + ":" + Environment.GetEnvironmentVariable("ALLEE_CLIENT_SECRET");
req.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(klient)));
req.Headers.Accept.ParseAdd("application/json");
req.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "authorization_code",
["code"] = "{kod_z_przekierowania}",
["redirect_uri"] = "https://integrator.example.com/allee/powrot",
["code_verifier"] = "{code_verifier}",
});
using var res = await http.SendAsync(req);
Console.WriteLine($"HTTP {(int)res.StatusCode}");
Console.WriteLine(await res.Content.ReadAsStringAsync());// allee API: POST /auth/oauth/token (Java 11+, java.net.http; uruchom: java Main.java)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Main {
public static void main(String[] args) throws Exception {
String base = System.getenv().getOrDefault("ALLEE_API_URL", "https://api.allee.pl");
String form = "grant_type=authorization_code&code=%7Bkod_z_przekierowania%7D&redirect_uri=https%3A%2F%2Fintegrator.example.com%2Fallee%2Fpowrot&code_verifier=%7Bcode_verifier%7D";
String klient = System.getenv("ALLEE_CLIENT_ID") + ":" + System.getenv("ALLEE_CLIENT_SECRET");
HttpRequest req = HttpRequest.newBuilder(URI.create(base + "/auth/oauth/token"))
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(klient.getBytes(StandardCharsets.UTF_8)))
.header("Accept", "application/json")
.header("Content-Type", "application/x-www-form-urlencoded")
.method("POST", HttpRequest.BodyPublishers.ofString(form))
.build();
HttpClient http = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println("HTTP " + res.statusCode());
System.out.println(res.body());
}
}// allee API: POST /auth/oauth/token (Go 1.20+, net/http; uruchom: go run main.go)
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
)
func main() {
base := os.Getenv("ALLEE_API_URL")
if base == "" {
base = "https://api.allee.pl"
}
form := url.Values{}
form.Set("grant_type", "authorization_code")
form.Set("code", "{kod_z_przekierowania}")
form.Set("redirect_uri", "https://integrator.example.com/allee/powrot")
form.Set("code_verifier", "{code_verifier}")
req, err := http.NewRequest("POST", base+"/auth/oauth/token", strings.NewReader(form.Encode()))
if err != nil {
panic(err)
}
req.SetBasicAuth(os.Getenv("ALLEE_CLIENT_ID"), os.Getenv("ALLEE_CLIENT_SECRET"))
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
klient := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
res, err := klient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
dane, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println("HTTP", res.StatusCode)
fmt.Println(string(dane))
}application/json{
"access_token": "{access_token}",
"token_type": "bearer",
"refresh_token": "{refresh_token}",
"expires_in": 43200,
"scope": "allegro:api:profile:read allegro:api:sale:offers:read allegro:api:sale:offers:write"
}Przykład: Odświeżenie tokenu (rotacja refresh tokenu)
curl -sS -X POST "${ALLEE_API_URL:-https://api.allee.pl}/auth/oauth/token" \
-u "$ALLEE_CLIENT_ID:$ALLEE_CLIENT_SECRET" \
-H "Accept: application/json" \
--data-urlencode "grant_type=refresh_token" \
--data-urlencode "refresh_token={refresh_token}" \
-w '\nHTTP %{http_code}\n'<?php
// allee API: POST /auth/oauth/token (PHP 8, rozszerzenie curl)
$base = getenv('ALLEE_API_URL') ?: 'https://api.allee.pl';
$ch = curl_init($base . '/auth/oauth/token');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Accept: application/json',
],
CURLOPT_USERPWD => getenv('ALLEE_CLIENT_ID') . ':' . getenv('ALLEE_CLIENT_SECRET'),
CURLOPT_POSTFIELDS => http_build_query([
'grant_type' => 'refresh_token',
'refresh_token' => '{refresh_token}',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$odp = curl_exec($ch);
echo 'HTTP ', curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $odp, "\n";# allee API: POST /auth/oauth/token (Python 3, biblioteka requests)
import os
import requests
BASE = os.environ.get("ALLEE_API_URL", "https://api.allee.pl")
headers = {
"Accept": "application/json",
}
form = {
"grant_type": "refresh_token",
"refresh_token": "{refresh_token}",
}
r = requests.request("POST", BASE + "/auth/oauth/token", headers=headers, data=form, auth=(os.environ["ALLEE_CLIENT_ID"], os.environ["ALLEE_CLIENT_SECRET"]), timeout=60, allow_redirects=False)
print("HTTP", r.status_code)
print(r.text)// allee API: POST /auth/oauth/token (Node.js 18+, wbudowany fetch; plik .mjs)
const BASE = process.env.ALLEE_API_URL ?? "https://api.allee.pl";
const form = new URLSearchParams({
"grant_type": "refresh_token",
"refresh_token": "{refresh_token}"
});
const res = await fetch(`${BASE}/auth/oauth/token`, {
method: "POST",
headers: {
Authorization: "Basic " + Buffer.from(`${process.env.ALLEE_CLIENT_ID}:${process.env.ALLEE_CLIENT_SECRET}`).toString("base64"),
"Accept": "application/json",
},
body: form,
redirect: "manual",
});
console.log("HTTP", res.status);
console.log(await res.text());// allee API: POST /auth/oauth/token (C#, .NET 8+, HttpClient)
using System.Net.Http.Headers;
using System.Text;
var baseUrl = Environment.GetEnvironmentVariable("ALLEE_API_URL") ?? "https://api.allee.pl";
using var http = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
using var req = new HttpRequestMessage(new HttpMethod("POST"), baseUrl + "/auth/oauth/token");
var klient = Environment.GetEnvironmentVariable("ALLEE_CLIENT_ID") + ":" + Environment.GetEnvironmentVariable("ALLEE_CLIENT_SECRET");
req.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(klient)));
req.Headers.Accept.ParseAdd("application/json");
req.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "refresh_token",
["refresh_token"] = "{refresh_token}",
});
using var res = await http.SendAsync(req);
Console.WriteLine($"HTTP {(int)res.StatusCode}");
Console.WriteLine(await res.Content.ReadAsStringAsync());// allee API: POST /auth/oauth/token (Java 11+, java.net.http; uruchom: java Main.java)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Main {
public static void main(String[] args) throws Exception {
String base = System.getenv().getOrDefault("ALLEE_API_URL", "https://api.allee.pl");
String form = "grant_type=refresh_token&refresh_token=%7Brefresh_token%7D";
String klient = System.getenv("ALLEE_CLIENT_ID") + ":" + System.getenv("ALLEE_CLIENT_SECRET");
HttpRequest req = HttpRequest.newBuilder(URI.create(base + "/auth/oauth/token"))
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(klient.getBytes(StandardCharsets.UTF_8)))
.header("Accept", "application/json")
.header("Content-Type", "application/x-www-form-urlencoded")
.method("POST", HttpRequest.BodyPublishers.ofString(form))
.build();
HttpClient http = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println("HTTP " + res.statusCode());
System.out.println(res.body());
}
}// allee API: POST /auth/oauth/token (Go 1.20+, net/http; uruchom: go run main.go)
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
)
func main() {
base := os.Getenv("ALLEE_API_URL")
if base == "" {
base = "https://api.allee.pl"
}
form := url.Values{}
form.Set("grant_type", "refresh_token")
form.Set("refresh_token", "{refresh_token}")
req, err := http.NewRequest("POST", base+"/auth/oauth/token", strings.NewReader(form.Encode()))
if err != nil {
panic(err)
}
req.SetBasicAuth(os.Getenv("ALLEE_CLIENT_ID"), os.Getenv("ALLEE_CLIENT_SECRET"))
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
klient := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
res, err := klient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
dane, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println("HTTP", res.StatusCode)
fmt.Println(string(dane))
}application/json{
"access_token": "{access_token}",
"token_type": "bearer",
"refresh_token": "{refresh_token}",
"expires_in": 43200,
"scope": "allegro:api:profile:read allegro:api:sale:offers:read allegro:api:sale:offers:write"
}Przykład: Token aplikacji (client_credentials) — tylko dane publiczne
curl -sS -X POST "${ALLEE_API_URL:-https://api.allee.pl}/auth/oauth/token" \
-u "$ALLEE_CLIENT_ID:$ALLEE_CLIENT_SECRET" \
-H "Accept: application/json" \
--data-urlencode "grant_type=client_credentials" \
-w '\nHTTP %{http_code}\n'<?php
// allee API: POST /auth/oauth/token (PHP 8, rozszerzenie curl)
$base = getenv('ALLEE_API_URL') ?: 'https://api.allee.pl';
$ch = curl_init($base . '/auth/oauth/token');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Accept: application/json',
],
CURLOPT_USERPWD => getenv('ALLEE_CLIENT_ID') . ':' . getenv('ALLEE_CLIENT_SECRET'),
CURLOPT_POSTFIELDS => http_build_query([
'grant_type' => 'client_credentials',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$odp = curl_exec($ch);
echo 'HTTP ', curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $odp, "\n";# allee API: POST /auth/oauth/token (Python 3, biblioteka requests)
import os
import requests
BASE = os.environ.get("ALLEE_API_URL", "https://api.allee.pl")
headers = {
"Accept": "application/json",
}
form = {
"grant_type": "client_credentials",
}
r = requests.request("POST", BASE + "/auth/oauth/token", headers=headers, data=form, auth=(os.environ["ALLEE_CLIENT_ID"], os.environ["ALLEE_CLIENT_SECRET"]), timeout=60, allow_redirects=False)
print("HTTP", r.status_code)
print(r.text)// allee API: POST /auth/oauth/token (Node.js 18+, wbudowany fetch; plik .mjs)
const BASE = process.env.ALLEE_API_URL ?? "https://api.allee.pl";
const form = new URLSearchParams({
"grant_type": "client_credentials"
});
const res = await fetch(`${BASE}/auth/oauth/token`, {
method: "POST",
headers: {
Authorization: "Basic " + Buffer.from(`${process.env.ALLEE_CLIENT_ID}:${process.env.ALLEE_CLIENT_SECRET}`).toString("base64"),
"Accept": "application/json",
},
body: form,
redirect: "manual",
});
console.log("HTTP", res.status);
console.log(await res.text());// allee API: POST /auth/oauth/token (C#, .NET 8+, HttpClient)
using System.Net.Http.Headers;
using System.Text;
var baseUrl = Environment.GetEnvironmentVariable("ALLEE_API_URL") ?? "https://api.allee.pl";
using var http = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
using var req = new HttpRequestMessage(new HttpMethod("POST"), baseUrl + "/auth/oauth/token");
var klient = Environment.GetEnvironmentVariable("ALLEE_CLIENT_ID") + ":" + Environment.GetEnvironmentVariable("ALLEE_CLIENT_SECRET");
req.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(klient)));
req.Headers.Accept.ParseAdd("application/json");
req.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "client_credentials",
});
using var res = await http.SendAsync(req);
Console.WriteLine($"HTTP {(int)res.StatusCode}");
Console.WriteLine(await res.Content.ReadAsStringAsync());// allee API: POST /auth/oauth/token (Java 11+, java.net.http; uruchom: java Main.java)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Main {
public static void main(String[] args) throws Exception {
String base = System.getenv().getOrDefault("ALLEE_API_URL", "https://api.allee.pl");
String form = "grant_type=client_credentials";
String klient = System.getenv("ALLEE_CLIENT_ID") + ":" + System.getenv("ALLEE_CLIENT_SECRET");
HttpRequest req = HttpRequest.newBuilder(URI.create(base + "/auth/oauth/token"))
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(klient.getBytes(StandardCharsets.UTF_8)))
.header("Accept", "application/json")
.header("Content-Type", "application/x-www-form-urlencoded")
.method("POST", HttpRequest.BodyPublishers.ofString(form))
.build();
HttpClient http = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println("HTTP " + res.statusCode());
System.out.println(res.body());
}
}// allee API: POST /auth/oauth/token (Go 1.20+, net/http; uruchom: go run main.go)
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
)
func main() {
base := os.Getenv("ALLEE_API_URL")
if base == "" {
base = "https://api.allee.pl"
}
form := url.Values{}
form.Set("grant_type", "client_credentials")
req, err := http.NewRequest("POST", base+"/auth/oauth/token", strings.NewReader(form.Encode()))
if err != nil {
panic(err)
}
req.SetBasicAuth(os.Getenv("ALLEE_CLIENT_ID"), os.Getenv("ALLEE_CLIENT_SECRET"))
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
klient := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
res, err := klient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
dane, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println("HTTP", res.StatusCode)
fmt.Println(string(dane))
}application/json{
"access_token": "{access_token}",
"token_type": "bearer",
"expires_in": 43200,
"scope": ""
}Odwołanie tokenu
POST /auth/oauth/revoke
tylko allee
Odwołanie access albo refresh tokenu (refresh → cała rodzina tokenów pary). Zawsze 200 po poprawnym uwierzytelnieniu klienta — nie zdradzamy, czy token istniał ani czyj był.
Zgodność: tylko allee — RFC 7009 (Allegro: brak).
Uwierzytelnienie: klient OAuth — Authorization: Basic base64(client_id:client_secret).
Treść żądania application/x-www-form-urlencoded
token string wymaganeToken do odwołania.
token_type_hint stringaccess_token, refresh_tokenOdpowiedzi
200 Odwołano (albo nic do odwołania). · RevokeResponse
revoked boolean zawszetrueBłędy
| HTTP | Kod | Znaczenie |
|---|---|---|
| 500 | INTERNAL_ERROR | Błąd serwera allee. |
curl -sS -X POST "${ALLEE_API_URL:-https://api.allee.pl}/auth/oauth/revoke" \
-u "$ALLEE_CLIENT_ID:$ALLEE_CLIENT_SECRET" \
-H "Accept: application/json" \
--data-urlencode "token={refresh_token}" \
--data-urlencode "token_type_hint=refresh_token" \
-w '\nHTTP %{http_code}\n'<?php
// allee API: POST /auth/oauth/revoke (PHP 8, rozszerzenie curl)
$base = getenv('ALLEE_API_URL') ?: 'https://api.allee.pl';
$ch = curl_init($base . '/auth/oauth/revoke');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Accept: application/json',
],
CURLOPT_USERPWD => getenv('ALLEE_CLIENT_ID') . ':' . getenv('ALLEE_CLIENT_SECRET'),
CURLOPT_POSTFIELDS => http_build_query([
'token' => '{refresh_token}',
'token_type_hint' => 'refresh_token',
]),
CURLOPT_RETURNTRANSFER => true,
]);
$odp = curl_exec($ch);
echo 'HTTP ', curl_getinfo($ch, CURLINFO_RESPONSE_CODE), "\n", $odp, "\n";# allee API: POST /auth/oauth/revoke (Python 3, biblioteka requests)
import os
import requests
BASE = os.environ.get("ALLEE_API_URL", "https://api.allee.pl")
headers = {
"Accept": "application/json",
}
form = {
"token": "{refresh_token}",
"token_type_hint": "refresh_token",
}
r = requests.request("POST", BASE + "/auth/oauth/revoke", headers=headers, data=form, auth=(os.environ["ALLEE_CLIENT_ID"], os.environ["ALLEE_CLIENT_SECRET"]), timeout=60, allow_redirects=False)
print("HTTP", r.status_code)
print(r.text)// allee API: POST /auth/oauth/revoke (Node.js 18+, wbudowany fetch; plik .mjs)
const BASE = process.env.ALLEE_API_URL ?? "https://api.allee.pl";
const form = new URLSearchParams({
"token": "{refresh_token}",
"token_type_hint": "refresh_token"
});
const res = await fetch(`${BASE}/auth/oauth/revoke`, {
method: "POST",
headers: {
Authorization: "Basic " + Buffer.from(`${process.env.ALLEE_CLIENT_ID}:${process.env.ALLEE_CLIENT_SECRET}`).toString("base64"),
"Accept": "application/json",
},
body: form,
redirect: "manual",
});
console.log("HTTP", res.status);
console.log(await res.text());// allee API: POST /auth/oauth/revoke (C#, .NET 8+, HttpClient)
using System.Net.Http.Headers;
using System.Text;
var baseUrl = Environment.GetEnvironmentVariable("ALLEE_API_URL") ?? "https://api.allee.pl";
using var http = new HttpClient(new HttpClientHandler { AllowAutoRedirect = false });
using var req = new HttpRequestMessage(new HttpMethod("POST"), baseUrl + "/auth/oauth/revoke");
var klient = Environment.GetEnvironmentVariable("ALLEE_CLIENT_ID") + ":" + Environment.GetEnvironmentVariable("ALLEE_CLIENT_SECRET");
req.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(klient)));
req.Headers.Accept.ParseAdd("application/json");
req.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
["token"] = "{refresh_token}",
["token_type_hint"] = "refresh_token",
});
using var res = await http.SendAsync(req);
Console.WriteLine($"HTTP {(int)res.StatusCode}");
Console.WriteLine(await res.Content.ReadAsStringAsync());// allee API: POST /auth/oauth/revoke (Java 11+, java.net.http; uruchom: java Main.java)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Main {
public static void main(String[] args) throws Exception {
String base = System.getenv().getOrDefault("ALLEE_API_URL", "https://api.allee.pl");
String form = "token=%7Brefresh_token%7D&token_type_hint=refresh_token";
String klient = System.getenv("ALLEE_CLIENT_ID") + ":" + System.getenv("ALLEE_CLIENT_SECRET");
HttpRequest req = HttpRequest.newBuilder(URI.create(base + "/auth/oauth/revoke"))
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(klient.getBytes(StandardCharsets.UTF_8)))
.header("Accept", "application/json")
.header("Content-Type", "application/x-www-form-urlencoded")
.method("POST", HttpRequest.BodyPublishers.ofString(form))
.build();
HttpClient http = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).build();
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
System.out.println("HTTP " + res.statusCode());
System.out.println(res.body());
}
}// allee API: POST /auth/oauth/revoke (Go 1.20+, net/http; uruchom: go run main.go)
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
)
func main() {
base := os.Getenv("ALLEE_API_URL")
if base == "" {
base = "https://api.allee.pl"
}
form := url.Values{}
form.Set("token", "{refresh_token}")
form.Set("token_type_hint", "refresh_token")
req, err := http.NewRequest("POST", base+"/auth/oauth/revoke", strings.NewReader(form.Encode()))
if err != nil {
panic(err)
}
req.SetBasicAuth(os.Getenv("ALLEE_CLIENT_ID"), os.Getenv("ALLEE_CLIENT_SECRET"))
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
klient := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
res, err := klient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
dane, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println("HTTP", res.StatusCode)
fmt.Println(string(dane))
}application/json{
"revoked": true
}