Validates a given API Key and issues an access token and refresh token pair when successful. Supports two modes - API Key Authentication and User Authentication.
For API Key Authentication, the Csc-Api-Key header is required.
For User Authentication, the projectId, username, and password parameters are required. If userPool is ommitted, it will be inferred.
Header Key | Description | Example |
---|---|---|
Csc-Api-Key | The API Key for this message. This is used as primary authentication with the server. | 571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiF... |
Content-Type | The content type for this request. | application/json |
Name | Type | Description |
---|---|---|
userPool | string | The user pool to authenticate against in User Authentication mode. |
projectId | uuid | The ID of the project to log the subject into. |
username | string | The name of the user. |
password | string | The password of the user. |
A successful response
Field Name | Type | Description |
---|---|---|
accessToken | string | The Access Token for the authenticated user. |
refreshToken | string | The Refresh Token for the authenticated user. |
identityIds | object |
curl \
-X POST "https://rest.eus.canaryspeech.com/v3/auth/tokens/get" \
-H "Csc-Api-Key: 571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1" \
-H "Content-Type: application/json" \
-d "{ }"
function postV3AuthTokensGet() {
const url = 'https://rest.eus.canaryspeech.com/v3/auth/tokens/get';
const headers = {
'Csc-Api-Key': '571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1',
'Content-Type': 'application/json'
};
const body = { };
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(body)
}).then((response) => {
if (!response.ok) throw new Error(response.status);
return response.json()
}).then((json) => {
const { accessToken, refreshToken, identityIds } = json;
// ...
});
}
const https = require('https');
function postV3AuthTokensGet() {
const headers = {
'Csc-Api-Key': '571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1',
'Content-Type': 'application/json'
};
const body = { };
const options = {
hostname: 'rest.eus.canaryspeech.com',
port: 443,
path: '/v3/auth/tokens/get',
method: 'POST',
headers: headers
};
const request = https.request(options, (response) => {
if (response.statusCode !== 200) throw new Error(response.statusCode);
response.on('data', (d) => {
const { accessToken, refreshToken, identityIds } = JSON.parse(d);
// ...
});
});
request.on('error', (err) => {
throw new Error(err);
});
request.write(JSON.stringify(body));
request.end();
}
const axios = require('axios').default;
async function postV3AuthTokensGet() {
const url = 'https://rest.eus.canaryspeech.com/v3/auth/tokens/get';
const headers = {
'Csc-Api-Key': '571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1',
'Content-Type': 'application/json'
};
const body = { };
const response = await axios.post(url, body, { headers });
if (response.status !== 200) throw new Error(response.status);
const { accessToken, refreshToken, identityIds } = response.data;
// ...
}
import * as https from 'https';
function postV3AuthTokensGet(): void {
const headers = {
'Csc-Api-Key': '571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1',
'Content-Type': 'application/json'
};
const body = { };
const options = {
hostname: 'rest.eus.canaryspeech.com',
port: 443,
path: '/v3/auth/tokens/get',
method: 'POST',
headers: headers
};
const request = https.request(options, (response) => {
if (response.statusCode !== 200) throw new Error(response.statusCode);
response.on('data', (d) => {
const { accessToken, refreshToken, identityIds } = JSON.parse(d) as Record<string, unknown>;
// ...
});
});
request.on('error', (err) => {
throw new Error(err);
});
request.write(JSON.stringify(body));
request.end();
}
import axios from 'axios';
async function postV3AuthTokensGet(): Promise<void> {
const url = 'https://rest.eus.canaryspeech.com/v3/auth/tokens/get';
const headers = {
'Csc-Api-Key': '571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1',
'Content-Type': 'application/json'
};
const body = { };
const response = await axios.post(url, body, { headers });
if (response.status !== 200) throw new Error(response.status);
const { accessToken, refreshToken, identityIds } = response.data;
// ...
}
import requests
def post_v3_auth_tokens_get():
url = 'https://rest.eus.canaryspeech.com/v3/auth/tokens/get'
headers = {
'Csc-Api-Key': '571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1',
'Content-Type': 'application/json'
}
body = { }
response = requests.post(
url,
headers=headers,
data=body,
)
if response.status_code !== 200:
raise Exception(response.status_code)
response_obj = response.json()
access_token = response_obj['accessToken']
refresh_token = response_obj['refreshToken']
identity_ids = response_obj['identityIds']
# ...
import org.json.simple.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.JSONParser;
import org.json.simple.JSONValue;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
public class CanarySpeechApi {
public void postV3AuthTokensGet() {
URI uri = new URI("https://rest.eus.canaryspeech.com/v3/auth/tokens/get");
JSONObject body = new JSONObject();
byte[] bodyBytes = JSONValue.toJSONString(body).getBytes(StandardCharsets.UTF_8);
HttpRequest request = HttpRequest.newBuilder()
.uri(uri)
.version(HttpClient.Version.HTTP_2)
.header("Csc-Api-Key", "571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1")
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofByteArray(bodyBytes))
.build();
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
if (client.status != 200) {
throw new Exception(client.status.toString());
}
JSONParser parser = new JSONParser();
JSONObject responseBody = (JSONObject) parser.parse(client.body());
String accessToken = (String) responseBody.get("accessToken");
String refreshToken = (String) responseBody.get("refreshToken");
Map<String, Object> identityIds = (Map<String, Object>) responseBody.get("identityIds");
// ...
}
}
import org.json.JSONObject
import java.lang.StringBuilder
import java.net.URL
import javax.net.ssl.HttpsURLConnection
suspend fun postV3AuthTokensGet() = runCatching {
val url = URL.create("https://rest.eus.canaryspeech.com/v3/auth/tokens/get")
with(url.openConnection() as HttpsURLConnection) {
requestMethod = "POST"
instanceFollowRedirects = true
setRequestProperty("Csc-Api-Key", "571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1")
setRequestProperty("Content-Type", "application/json")
doInput = true
setChunkedStreamingMode(0)
val body = JSONObject()
outputStream.bufferedWriter(Charsets.UTF_8).use {
it.write(body.toString())
it.flush()
}
doOutput = true
if (responseCode != 200) throw Error(responseMessage)
val buffer = StringBuilder()
var line: String?
inputStream.bufferedReader(Charsets.UTF-8).use {
do {
line = it.readLine()
if (line != null) buffer.appendLine(line)
} while (line != null)
}
val responseBody = JSONObject(buffer.toString())
val accessToken = responseBody.get("accessToken") as String
val refreshToken = responseBody.get("refreshToken") as String
val identityIds = responseBody.get("identityIds") as Map<String, Any?>
// ...
}
}
import UIKit
func postV3AuthTokensGet() -> void {
let url = URL("https://rest.eus.canaryspeech.com/v3/auth/tokens/get")
let headers: [String: String] = [
"Csc-Api-Key": "571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1",
"Content-Type": "application/json"
]
let body: [String: Any] = [ ]
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = JSONEncoder().encode(body)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard
let data = data,
let response = response as? HTTPURLResponse,
error == nil
else {
print("error", error ?? URLError(.badServerResponse)
return
}
guard (200 ... 299) ~= response.statusCode else {
print("statusCode = \(response.statusCode)")
print("response = \(response)")
return
}
do {
let responseObj = try JSONDecoder().decode(PostV3AuthTokensGetResponse.self, data)
// ...
} catch {
print(error)
}
}
}
}
struct PostV3AuthTokensGetResponse: Decodable {
let accessToken: String
let refreshToken: String
let identityIds: [String: Any]
}
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Encoding;
using System.Text.Json;
using System.Text.Json.Serialization;
public static class CanarySpeechAPI
{
public static readonly HttpClient client = new HttpClient();
public static async Task postV3AuthTokensGet()
{
var url = "https://rest.eus.canaryspeech.com/v3/auth/tokens/get\"";
var body = new Dictionary<string, dynamic> { };
var bodyString = JsonConvert.Serialize(body);
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Add("Csc-Api-Key", "571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1");
request.Headers.Add("Content-Type", "application/json");
request.Content = new ByteArrayContent(Encoding.UTF8.GetBytes(bodyString));
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var responseJson = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(responseBody);
var accessToken = (String)responseJson["accessToken"];
var refreshToken = (String)responseJson["refreshToken"];
var identityIds = (Dictionary<String, dynamic>)responseJson["identityIds"];
// ...
}
}
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<void> function postV3AuthTokensGet() async {
final uri = Uri.https('rest.eus.canaryspeech.com', 'v3/auth/tokens/get', queryParams);
final headers = {
'Csc-Api-Key': '571CCF:SvJtIepDIolHFZMby7OuGPd9kYwJaWJ18Bp5/Q+6yiFn0FR1',
'Content-Type': 'application/json'
};
final body = { };
final request = http.Request('POST', uri);
request.headers.addAll(headers)
request.body = json.encode(body);
final client = http.Client();
try {
final responseStream = await client.send(request);
final statusCode = responseStream.statusCode;
if (statusCode < 200 || statusCode >= 300) {
throw Error(statusCode.toString());
}
final responseBytes = await responseStream.stream.toBytes();
final responseString = utf8.decode(responseBytes);
final response = json.decode(responseString);
final accessToken = response['accessToken'] as String;
final refreshToken = response['refreshToken'] as String;
final identityIds = response['identityIds'] as Map<String, dynamic>;
// ...
} catch (e) {
print(e);
}
}
The user pool to authenticate against in User Authentication mode.
Enum | Type | Description |
---|---|---|
"subjects" | string | |
"users" | string |
Name | Type | Description |
---|---|---|
clientId | uuid | The client ID for the user's authentication context. |
projectId | uuid | The project ID for the user's authentication context. May be "*" if the context allows access to multiple projects. |
subjectId | uuid | The subject ID for the user's authentication context. May be "*" if the context allows access to multiple subjects. |