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

# Exchange SSO token

POST /v1/sso_token
Content-Type: application/json

Exchange an OpenID Connect ID token or access token for an
Ocient database access token.

This endpoint allows clients to directly exchange tokens without going through
the full browser-based authentication flow. This is useful for server-to-server
scenarios or when the client already has a valid OpenID token from another flow.

### Example

```bash
curl -X POST https://your-ocient-instance/v1/sso_token \
  -H "Content-Type: application/json" \
  -d '{
    "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
    "database": "retail_analytics"
  }'
```

Reference: https://ocient.ferndocs.com/api-reference/sso-integration/ssotoken

## Request

### Body (application/json)

This endpoint expects a SSOTokenRequest.

- `SSOTokenRequest`
  - any
  - any

## Response

### 200

Token exchange successful

- `access_token` (string, required) — Access token for subsequent API calls. This token should be included in the Authorization header for all authenticated requests using the format: `Authorization: Bearer {token}`.
- `status` (Status, required) — Status information about the login operation. A successful login will have a SQL state of "00000".
- `username` (string, optional) — The authenticated user's username. This is useful for displaying in UIs or for audit logging purposes.
- `database` (string, optional) — The database that was authenticated against. This is the default database for subsequent queries if none is specified.
- `expires_in` (integer, optional) — Number of seconds until the access token expires. Clients should refresh the token before this time to maintain uninterrupted access.

## Errors

### 401 Unauthorized Error

Unauthorized

- `status` (Status, required)

## Types

### Status

- `reason` (string, required) — Human-readable description of the operation result
- `sql_state` (string, required) — SQL state code (see Error Handling section for common codes)
- `vendor_code` (integer, required) — Vendor-specific error code

## Examples

### Successful Token Exchange Response

**Response**

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqZG9lIiwiZGIiOiJyZXRhaWxfYW5hbHl0aWNzIiwiZXhwIjoxNjM1NDYxNzEyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
  "status": {
    "reason": "Authentication successful",
    "sql_state": "00000",
    "vendor_code": 0
  },
  "username": "jdoe",
  "database": "retail_analytics"
}
```

**SDK Code**

```python Successful Token Exchange Response
import requests

url = "https://v1/sso_token"

response = requests.post(url)

print(response.json())
```

```javascript Successful Token Exchange Response
const url = 'https://v1/sso_token';
const options = {method: 'POST'};

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

```go Successful Token Exchange Response
package main

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

func main() {

	url := "https://v1/sso_token"

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

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Successful Token Exchange Response
require 'uri'
require 'net/http'

url = URI("https://v1/sso_token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

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

```java Successful Token Exchange Response
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://v1/sso_token")
  .asString();
```

```php Successful Token Exchange Response
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1/sso_token');

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

```csharp Successful Token Exchange Response
using RestSharp;

var client = new RestClient("https://v1/sso_token");
var request = new RestRequest(Method.POST);
IRestResponse response = client.Execute(request);
```

```swift Successful Token Exchange Response
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "https://v1/sso_token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"

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()
```

### ID Token Exchange

**Request**

```json
{
  "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "database": "retail_analytics"
}
```

**Response**

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqZG9lIiwiZGIiOiJyZXRhaWxfYW5hbHl0aWNzIiwiZXhwIjoxNjM1NDYxNzEyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
  "status": {
    "reason": "Authentication successful",
    "sql_state": "00000",
    "vendor_code": 0
  },
  "username": "jdoe",
  "database": "retail_analytics"
}
```

**SDK Code**

```python ID Token Exchange
import requests

url = "https://v1/sso_token"

payload = {
    "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
    "database": "retail_analytics"
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript ID Token Exchange
const url = 'https://v1/sso_token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"id_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...","database":"retail_analytics"}'
};

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

```go ID Token Exchange
package main

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

func main() {

	url := "https://v1/sso_token"

	payload := strings.NewReader("{\n  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"database\": \"retail_analytics\"\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(res)
	fmt.Println(string(body))

}
```

```ruby ID Token Exchange
require 'uri'
require 'net/http'

url = URI("https://v1/sso_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  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"database\": \"retail_analytics\"\n}"

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

```java ID Token Exchange
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://v1/sso_token")
  .header("Content-Type", "application/json")
  .body("{\n  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"database\": \"retail_analytics\"\n}")
  .asString();
```

```php ID Token Exchange
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1/sso_token', [
  'body' => '{
  "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "database": "retail_analytics"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp ID Token Exchange
using RestSharp;

var client = new RestClient("https://v1/sso_token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"database\": \"retail_analytics\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift ID Token Exchange
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "database": "retail_analytics"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://v1/sso_token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```

### Access Token Exchange

**Request**

```json
{
  "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "access_token": "ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...",
  "database": "retail_analytics"
}
```

**Response**

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJqZG9lIiwiZGIiOiJyZXRhaWxfYW5hbHl0aWNzIiwiZXhwIjoxNjM1NDYxNzEyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
  "status": {
    "reason": "Authentication successful",
    "sql_state": "00000",
    "vendor_code": 0
  },
  "username": "jdoe",
  "database": "retail_analytics"
}
```

**SDK Code**

```python Access Token Exchange
import requests

url = "https://v1/sso_token"

payload = {
    "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
    "access_token": "ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...",
    "database": "retail_analytics"
}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript Access Token Exchange
const url = 'https://v1/sso_token';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"id_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...","access_token":"ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...","database":"retail_analytics"}'
};

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

```go Access Token Exchange
package main

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

func main() {

	url := "https://v1/sso_token"

	payload := strings.NewReader("{\n  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"access_token\": \"ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...\",\n  \"database\": \"retail_analytics\"\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(res)
	fmt.Println(string(body))

}
```

```ruby Access Token Exchange
require 'uri'
require 'net/http'

url = URI("https://v1/sso_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  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"access_token\": \"ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...\",\n  \"database\": \"retail_analytics\"\n}"

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

```java Access Token Exchange
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://v1/sso_token")
  .header("Content-Type", "application/json")
  .body("{\n  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"access_token\": \"ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...\",\n  \"database\": \"retail_analytics\"\n}")
  .asString();
```

```php Access Token Exchange
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1/sso_token', [
  'body' => '{
  "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "access_token": "ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...",
  "database": "retail_analytics"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Access Token Exchange
using RestSharp;

var client = new RestClient("https://v1/sso_token");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"id_token\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...\",\n  \"access_token\": \"ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...\",\n  \"database\": \"retail_analytics\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Access Token Exchange
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "id_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "access_token": "ya29.a0AfH6SMBx-CyHfZyrdH9d_dKwMmL8LjM...",
  "database": "retail_analytics"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://v1/sso_token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

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()
```