curl --request POST \
--url https://api.example.com/v1/oauth/token \
--header 'Content-Type: application/json' \
--data '
{
"client_id": "",
"code": null,
"code_verifier": null,
"device_code": null,
"grant_type": "",
"redirect_uri": null,
"refresh_token": null
}
'import requests
url = "https://api.example.com/v1/oauth/token"
payload = {
"client_id": "",
"code": None,
"code_verifier": None,
"device_code": None,
"grant_type": "",
"redirect_uri": None,
"refresh_token": None
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
client_id: '',
code: null,
code_verifier: null,
device_code: null,
grant_type: '',
redirect_uri: null,
refresh_token: null
})
};
fetch('https://api.example.com/v1/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://api.example.com/v1/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 => json_encode([
'client_id' => '',
'code' => null,
'code_verifier' => null,
'device_code' => null,
'grant_type' => '',
'redirect_uri' => null,
'refresh_token' => null
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.example.com/v1/oauth/token"
payload := strings.NewReader("{\n \"client_id\": \"\",\n \"code\": null,\n \"code_verifier\": null,\n \"device_code\": null,\n \"grant_type\": \"\",\n \"redirect_uri\": null,\n \"refresh_token\": null\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
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.example.com/v1/oauth/token")
.header("Content-Type", "application/json")
.body("{\n \"client_id\": \"\",\n \"code\": null,\n \"code_verifier\": null,\n \"device_code\": null,\n \"grant_type\": \"\",\n \"redirect_uri\": null,\n \"refresh_token\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/oauth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"client_id\": \"\",\n \"code\": null,\n \"code_verifier\": null,\n \"device_code\": null,\n \"grant_type\": \"\",\n \"redirect_uri\": null,\n \"refresh_token\": null\n}"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"expires_in": 123,
"refresh_token": "<string>",
"scope": "<string>",
"token_type": "<string>"
}{
"error": "<string>",
"error_description": "<string>"
}POST /v1/oauth/token
curl --request POST \
--url https://api.example.com/v1/oauth/token \
--header 'Content-Type: application/json' \
--data '
{
"client_id": "",
"code": null,
"code_verifier": null,
"device_code": null,
"grant_type": "",
"redirect_uri": null,
"refresh_token": null
}
'import requests
url = "https://api.example.com/v1/oauth/token"
payload = {
"client_id": "",
"code": None,
"code_verifier": None,
"device_code": None,
"grant_type": "",
"redirect_uri": None,
"refresh_token": None
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
client_id: '',
code: null,
code_verifier: null,
device_code: null,
grant_type: '',
redirect_uri: null,
refresh_token: null
})
};
fetch('https://api.example.com/v1/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://api.example.com/v1/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 => json_encode([
'client_id' => '',
'code' => null,
'code_verifier' => null,
'device_code' => null,
'grant_type' => '',
'redirect_uri' => null,
'refresh_token' => null
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$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.example.com/v1/oauth/token"
payload := strings.NewReader("{\n \"client_id\": \"\",\n \"code\": null,\n \"code_verifier\": null,\n \"device_code\": null,\n \"grant_type\": \"\",\n \"redirect_uri\": null,\n \"refresh_token\": null\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
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.example.com/v1/oauth/token")
.header("Content-Type", "application/json")
.body("{\n \"client_id\": \"\",\n \"code\": null,\n \"code_verifier\": null,\n \"device_code\": null,\n \"grant_type\": \"\",\n \"redirect_uri\": null,\n \"refresh_token\": null\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/oauth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"client_id\": \"\",\n \"code\": null,\n \"code_verifier\": null,\n \"device_code\": null,\n \"grant_type\": \"\",\n \"redirect_uri\": null,\n \"refresh_token\": null\n}"
response = http.request(request)
puts response.read_body{
"access_token": "<string>",
"expires_in": 123,
"refresh_token": "<string>",
"scope": "<string>",
"token_type": "<string>"
}{
"error": "<string>",
"error_description": "<string>"
}请求体
RFC 6749 §4.1.3 / §6 and RFC 8628 §3.4, in one shape.
Which fields must be present depends on grant_type, so all of them are
optional here and the issuer names what is missing. That is deliberate: a
client that sends code with grant_type=refresh_token deserves
invalid_request: refresh_token is required, not a parse error listing
every field of every grant type.
Required for every grant type. These are public clients — there is no client secret to authenticate with — so this names the client and is checked against the grant, never trusted on its own.
authorization_code, refresh_token or [DEVICE_GRANT_TYPE].
响应
Success
RFC 6749 §5.1. Both token values are plaintext and exist only here.
The access token's remaining lifetime, in seconds.
Rotated on every exchange: the one presented is consumed and this one
replaces it. Presenting a consumed refresh token revokes the whole
grant — see [crate::operations::issuer].
The granted scopes, space-delimited, as they are recorded on the grant.
Always [TOKEN_TYPE].