Exchange credentials for tokens
Supports password, refresh_token, and magic_link grant types. In the future, we will support OAuth Authorization Code grant type.
POST
/
v1
/
auth
/
token
Exchange credentials for tokens
curl --request POST \
--url https://api.kerne.io/v1/auth/token \
--header 'Content-Type: application/json' \
--header 'x-app-id: <api-key>' \
--data '
{
"grant_type": "password",
"email": "[email protected]",
"password": "SecurePassword123!",
"refresh_token": "ref_0123456789abcdef",
"token": "ml_0123456789abcdef",
"scope": "openid profile email"
}
'import requests
url = "https://api.kerne.io/v1/auth/token"
payload = {
"grant_type": "password",
"email": "[email protected]",
"password": "SecurePassword123!",
"refresh_token": "ref_0123456789abcdef",
"token": "ml_0123456789abcdef",
"scope": "openid profile email"
}
headers = {
"x-app-id": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-app-id': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
grant_type: 'password',
email: '[email protected]',
password: 'SecurePassword123!',
refresh_token: 'ref_0123456789abcdef',
token: 'ml_0123456789abcdef',
scope: 'openid profile email'
})
};
fetch('https://api.kerne.io/v1/auth/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.kerne.io/v1/auth/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([
'grant_type' => 'password',
'email' => '[email protected]',
'password' => 'SecurePassword123!',
'refresh_token' => 'ref_0123456789abcdef',
'token' => 'ml_0123456789abcdef',
'scope' => 'openid profile email'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-app-id: <api-key>"
],
]);
$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.kerne.io/v1/auth/token"
payload := strings.NewReader("{\n \"grant_type\": \"password\",\n \"email\": \"[email protected]\",\n \"password\": \"SecurePassword123!\",\n \"refresh_token\": \"ref_0123456789abcdef\",\n \"token\": \"ml_0123456789abcdef\",\n \"scope\": \"openid profile email\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-app-id", "<api-key>")
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.kerne.io/v1/auth/token")
.header("x-app-id", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"grant_type\": \"password\",\n \"email\": \"[email protected]\",\n \"password\": \"SecurePassword123!\",\n \"refresh_token\": \"ref_0123456789abcdef\",\n \"token\": \"ml_0123456789abcdef\",\n \"scope\": \"openid profile email\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.kerne.io/v1/auth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-app-id"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"grant_type\": \"password\",\n \"email\": \"[email protected]\",\n \"password\": \"SecurePassword123!\",\n \"refresh_token\": \"ref_0123456789abcdef\",\n \"token\": \"ml_0123456789abcdef\",\n \"scope\": \"openid profile email\"\n}"
response = http.request(request)
puts response.read_body{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "usr_01234567890abcdef",
"email": "[email protected]"
},
"refresh_token": "ref_0123456789abcdef",
"expires_at": "2025-01-01T01:00:00.000Z"
}Authorizations
App identifier (App.id, sent as the x-app-id header)
Body
application/json
Grant type for token exchange
Available options:
password, refresh_token, magic_link Example:
"password"
Example:
Example:
"SecurePassword123!"
Example:
"ref_0123456789abcdef"
Magic link token
Example:
"ml_0123456789abcdef"
Requested scopes (space separated)
Example:
"openid profile email"
Response
200 - application/json
JWT authentication token
Example:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
Authenticated user information
Show child attributes
Show child attributes
Refresh token for obtaining new access tokens
Example:
"ref_0123456789abcdef"
Token expiration timestamp (ISO)
Example:
"2025-01-01T01:00:00.000Z"
⌘I
Exchange credentials for tokens
curl --request POST \
--url https://api.kerne.io/v1/auth/token \
--header 'Content-Type: application/json' \
--header 'x-app-id: <api-key>' \
--data '
{
"grant_type": "password",
"email": "[email protected]",
"password": "SecurePassword123!",
"refresh_token": "ref_0123456789abcdef",
"token": "ml_0123456789abcdef",
"scope": "openid profile email"
}
'import requests
url = "https://api.kerne.io/v1/auth/token"
payload = {
"grant_type": "password",
"email": "[email protected]",
"password": "SecurePassword123!",
"refresh_token": "ref_0123456789abcdef",
"token": "ml_0123456789abcdef",
"scope": "openid profile email"
}
headers = {
"x-app-id": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-app-id': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
grant_type: 'password',
email: '[email protected]',
password: 'SecurePassword123!',
refresh_token: 'ref_0123456789abcdef',
token: 'ml_0123456789abcdef',
scope: 'openid profile email'
})
};
fetch('https://api.kerne.io/v1/auth/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.kerne.io/v1/auth/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([
'grant_type' => 'password',
'email' => '[email protected]',
'password' => 'SecurePassword123!',
'refresh_token' => 'ref_0123456789abcdef',
'token' => 'ml_0123456789abcdef',
'scope' => 'openid profile email'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-app-id: <api-key>"
],
]);
$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.kerne.io/v1/auth/token"
payload := strings.NewReader("{\n \"grant_type\": \"password\",\n \"email\": \"[email protected]\",\n \"password\": \"SecurePassword123!\",\n \"refresh_token\": \"ref_0123456789abcdef\",\n \"token\": \"ml_0123456789abcdef\",\n \"scope\": \"openid profile email\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-app-id", "<api-key>")
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.kerne.io/v1/auth/token")
.header("x-app-id", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"grant_type\": \"password\",\n \"email\": \"[email protected]\",\n \"password\": \"SecurePassword123!\",\n \"refresh_token\": \"ref_0123456789abcdef\",\n \"token\": \"ml_0123456789abcdef\",\n \"scope\": \"openid profile email\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.kerne.io/v1/auth/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-app-id"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"grant_type\": \"password\",\n \"email\": \"[email protected]\",\n \"password\": \"SecurePassword123!\",\n \"refresh_token\": \"ref_0123456789abcdef\",\n \"token\": \"ml_0123456789abcdef\",\n \"scope\": \"openid profile email\"\n}"
response = http.request(request)
puts response.read_body{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "usr_01234567890abcdef",
"email": "[email protected]"
},
"refresh_token": "ref_0123456789abcdef",
"expires_at": "2025-01-01T01:00:00.000Z"
}
