Docs Guides
Authentication
Login tokens for people, API keys for servers, and what each may do.
There are two kinds of credential. Both identify exactly one tenant; you never send a tenant id on requests.
| Login token | API key | |
|---|---|---|
| For | A person using your app | Your backend |
| Header | Authorization: Bearer <token> |
X-API-Key: nbl_<prefix>.<secret> |
| Lifetime | 1 hour | Until revoked or expiresAt |
| Permissions | The person’s platform role | Scopes: read, write |
Signing a person in#
curl -X POST "$LMS_URL/api/v1/auth/login" \
-H "Content-Type: application/json" \
-d '{
"tenant": "acme",
"email": "ada@acme.example",
"password": "a-long-password"
}'const LMS_URL = process.env.LMS_URL
const res = await fetch(`${LMS_URL}/api/v1/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"tenant": "acme",
"email": "ada@acme.example",
"password": "a-long-password"
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data = await res.json()const LMS_URL = process.env.LMS_URL!
const res = await fetch(`${LMS_URL}/api/v1/auth/login`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"tenant": "acme",
"email": "ada@acme.example",
"password": "a-long-password"
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data: unknown = await res.json()import os
import requests
LMS_URL = os.environ["LMS_URL"]
res = requests.post(f"{LMS_URL}/api/v1/auth/login", json={
"tenant": "acme",
"email": "ada@acme.example",
"password": "a-long-password",
}, timeout=10)
res.raise_for_status()
data = res.json()import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Request {
public static void main(String[] args) throws Exception {
String lmsUrl = System.getenv("LMS_URL");
String body = """
{
"tenant": "acme",
"email": "ada@acme.example",
"password": "a-long-password"
}
""";
var request = HttpRequest.newBuilder(URI.create(lmsUrl + "/api/v1/auth/login"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.statusCode() + " " + response.body());
System.out.println(response.body());
}
}require "net/http"
require "json"
lms_url = ENV.fetch("LMS_URL")
uri = URI("#{lms_url}/api/v1/auth/login")
request = Net::HTTP::Post.new(uri, "Content-Type" => "application/json")
request.body = {
"tenant" => "acme",
"email" => "ada@acme.example",
"password" => "a-long-password",
}.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
raise "#{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)<?php
$lmsUrl = getenv('LMS_URL');
$ch = curl_init("$lmsUrl/api/v1/auth/login");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
"tenant" => "acme",
"email" => "ada@acme.example",
"password" => "a-long-password",
]),
]);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 300) {
throw new RuntimeException($response);
}
$data = json_decode($response, true);package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`{
"tenant": "acme",
"email": "ada@acme.example",
"password": "a-long-password"
}`)
req, _ := http.NewRequest("POST", os.Getenv("LMS_URL") + "/api/v1/auth/login", body)
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
if res.StatusCode >= 300 {
panic(fmt.Sprintf("%d %s", res.StatusCode, data))
}
fmt.Println(string(data))
}{ "accessToken": "eyJ...", "expiresInSeconds": 3600 }
Every failure returns the same 401, so the endpoint can’t be used to find out who has an account. There are no refresh tokens yet: sign in again when the token expires.
API keys#
Create one as a signed-in admin with POST /api-keys. The full key is returned once; only a hash is stored.
curl -X POST "$LMS_URL/api/v1/api-keys" \
-H "Authorization: Bearer $LMS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Website checkout",
"scopes": [
"read",
"write"
]
}'const LMS_URL = process.env.LMS_URL
const LMS_TOKEN = process.env.LMS_TOKEN
const res = await fetch(`${LMS_URL}/api/v1/api-keys`, {
method: 'POST',
headers: { "Authorization": `Bearer ${LMS_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"name": "Website checkout",
"scopes": [
"read",
"write"
]
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data = await res.json()const LMS_URL = process.env.LMS_URL!
const LMS_TOKEN = process.env.LMS_TOKEN!
const res = await fetch(`${LMS_URL}/api/v1/api-keys`, {
method: 'POST',
headers: { "Authorization": `Bearer ${LMS_TOKEN}`, 'Content-Type': 'application/json' },
body: JSON.stringify({
"name": "Website checkout",
"scopes": [
"read",
"write"
]
}),
})
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`)
const data: unknown = await res.json()import os
import requests
LMS_URL = os.environ["LMS_URL"]
HEADERS = {"Authorization": "Bearer " + os.environ["LMS_TOKEN"]}
res = requests.post(f"{LMS_URL}/api/v1/api-keys", headers=HEADERS, json={
"name": "Website checkout",
"scopes": [
"read",
"write",
],
}, timeout=10)
res.raise_for_status()
data = res.json()import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Request {
public static void main(String[] args) throws Exception {
String lmsUrl = System.getenv("LMS_URL");
String lmsToken = System.getenv("LMS_TOKEN");
String body = """
{
"name": "Website checkout",
"scopes": [
"read",
"write"
]
}
""";
var request = HttpRequest.newBuilder(URI.create(lmsUrl + "/api/v1/api-keys"))
.header("Authorization", "Bearer " + lmsToken)
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString(body))
.build();
var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.statusCode() + " " + response.body());
System.out.println(response.body());
}
}require "net/http"
require "json"
lms_url = ENV.fetch("LMS_URL")
uri = URI("#{lms_url}/api/v1/api-keys")
request = Net::HTTP::Post.new(uri, "Authorization" => "Bearer " + ENV.fetch("LMS_TOKEN"), "Content-Type" => "application/json")
request.body = {
"name" => "Website checkout",
"scopes" => [
"read",
"write",
],
}.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(request) }
raise "#{response.code} #{response.body}" unless response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)<?php
$lmsUrl = getenv('LMS_URL');
$ch = curl_init("$lmsUrl/api/v1/api-keys");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('LMS_TOKEN'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
"name" => "Website checkout",
"scopes" => [
"read",
"write",
],
]),
]);
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 300) {
throw new RuntimeException($response);
}
$data = json_decode($response, true);package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`{
"name": "Website checkout",
"scopes": [
"read",
"write"
]
}`)
req, _ := http.NewRequest("POST", os.Getenv("LMS_URL") + "/api/v1/api-keys", body)
req.Header.Set("Authorization", "Bearer " + os.Getenv("LMS_TOKEN"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
data, _ := io.ReadAll(res.Body)
if res.StatusCode >= 300 {
panic(fmt.Sprintf("%d %s", res.StatusCode, data))
}
fmt.Println(string(data))
}Important
Keep keys on your server. Never ship one in a browser or mobile app. A key can’t create or revoke other keys, and it can’t call the learner (/me) endpoints directly because those belong to a person. To act for one of your users, ask for a learner token (next section).
Acting for your own users#
If your application has its own users, you don’t give them LMS passwords. When one of them opens a course, your server uses its API key to call POST /learners/{your-user-id}/session. That creates or updates the person, enrols them in the courses you list, and returns a token that lasts an hour and can only act as that one person. Your front end uses the token for the learner API.
Tokens are only issued for active accounts whose only role is LEARNER, so a key can never act as an admin or instructor. The Quickstart walks through it.
Platform roles#
| Role | May |
|---|---|
ADMIN |
Everything in the tenant. |
INSTRUCTOR |
Read content, grade essays, view progress. |
LEARNER |
Use the learner API for their own enrollments. |
Organization managers can additionally invite people to, and see the progress of, their own organization. Each endpoint’s Access line in the reference says exactly who may call it.
Checking a credential#
GET /auth/me returns the tenant, the kind of credential, its id and its authorities.