> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.wynncraft.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.wynncraft.com/_mcp/server.

# Exchange OAuth2 token

POST https://api.wynncraft.com/v3/oauth/token
Content-Type: application/x-www-form-urlencoded

This endpoint expects `application/x-www-form-urlencoded`.

Try it will not return usable data for this route. It depends on a live OAuth2 authentication context outside the docs.

Get started with OAuth by reading [our guide](/oauth2/creating-an-application).

Only the `authorization_code` grant type is supported. Authorization codes are one-time use and expire after 5 minutes.

PKCE is supported for both Private and Public applications but Public applications must send `code_verifier` and must not send `client_secret`.

Private applications must send `client_secret`.

Only `S256` PKCE is supported.

Reference: https://docs.wynncraft.com/modules/o-auth-2/exchange-oauth-token

## Request

### Body (application/x-www-form-urlencoded)

This endpoint expects an OAuthTokenExchangeRequest.

- `grant_type` (enum, required) — Only `authorization_code` is supported.
  - Allowed values: `authorization_code`
- `code` (string, required) — One-time authorization code. Expires after 5 minutes.
- `redirect_uri` (string, required) — Must match the redirect URI used during authorization.
- `client_id` (string, required)
- `client_secret` (string, optional) — Required for private applications. Must not be sent by public applications.
- `code_verifier` (string, optional) — Required for public applications and for any authorization code created with PKCE.

## Response

### 200

OAuth2 access token exchange result.

- `access_token` (string, required)
- `token_type` (enum, required)
  - Allowed values: `bearer`
- `scope` (string, required) — Space-delimited granted scopes.

## Examples

**Request**

```json
{
  "grant_type": "authorization_code",
  "code": "string",
  "redirect_uri": "string",
  "client_id": "string"
}
```

**Response**

```json
{
  "access_token": "wgc_g37VxyznaVYuUtjWyA54fgoC_qG-cIDNjVhM-FG",
  "token_type": "bearer",
  "scope": "identify main_access"
}
```

**SDK Code**

```python Authorization code exchange success response
import requests

url = "https://api.wynncraft.com/v3/oauth/token"

payload = ""
headers = {"Content-Type": "application/x-www-form-urlencoded"}

response = requests.post(url, data=payload, headers=headers)

print(response.json())
```

```javascript Authorization code exchange success response
const url = 'https://api.wynncraft.com/v3/oauth/token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  body: new URLSearchParams('')
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Authorization code exchange success response
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.wynncraft.com/v3/oauth/token"

	req, _ := http.NewRequest("POST", url, nil)

	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(res)
	fmt.Println(string(body))

}
```

```ruby Authorization code exchange success response
require 'uri'
require 'net/http'

url = URI("https://api.wynncraft.com/v3/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'

response = http.request(request)
puts response.read_body
```

```java Authorization code exchange success response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.wynncraft.com/v3/oauth/token")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .asString();
```

```php Authorization code exchange success response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.wynncraft.com/v3/oauth/token', [
  'form_params' => null,
  'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
]);

echo $response->getBody();
```

```csharp Authorization code exchange success response
using RestSharp;

var client = new RestClient("https://api.wynncraft.com/v3/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
```

```swift Authorization code exchange success response
import Foundation

let headers = ["Content-Type": "application/x-www-form-urlencoded"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.wynncraft.com/v3/oauth/token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```