Authentication

The TokenOS API uses API keys to authenticate requests. You can view and manage your API keys in the TokenOS Dashboard.

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

Authentication to the API is performed via HTTP basic auth, HTTP body auth, or JWT bearer auth. All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.

Basic Auth

For HTTP basic auth, the client sends its client ID and client secret as part of the authorization header in an HTTP request. The Authorization header contains a Base-64 encoded string of {URL-encoded-client-ID}:{URL-encoded-client-secret}.

const clientID = "the-client-id"
const clientSecret = "the-secret-id"
const basicAuth = bas64_encode(url_encode(clientID) + ":" + url_encode(clientSecret))

const requestOptions = {
  method: "POST",
  headers: {
    Authorization: "Basic " + basicAuth,
    "Content-Type": "application/x-www-form-urlencoded",
  },
  body: "grant_type=client_credentials&scope=read",
}

fetch("https://your-project.projects.oryapis.com/oauth2/token", requestOptions)
  .then((response) => response.json())
  .then((data) => console.log(data))

JWT Bearer Auth

For JWT bearer auth, this method is similar to basic and body authentication, but instead of sending the client ID and client secret, the client sends a JSON Web Token (JWT) which was signed by its cryptographic key.

const clientID = "the-client-id"
const clientSecret = "the-secret-id"

const qs = new URLSearchParams()
qs.set("grant_type", "client_credentials")
qs.set("client_id", clientID)
qs.set("client_secret", clientSecret)
qs.set("scope", read)

const requestOptions = {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: qs.toString(),
}

fetch("https://your-project.projects.oryapis.com/oauth2/token", requestOptions)
  .then((response) => response.json())
  .then((data) => console.log(data))

Enhanced Security Authentication

For clients requiring enhanced security, we do offer

Last updated