Files
stephen schuresko bd40b4f850 Add darktable REST API implementation
- Introduced a new Lua-based REST API for darktable, allowing external applications to interact with the darktable library.
- Implemented core functionalities including image listing, retrieval, and preview serving.
- Added support for OAuth 2.0 authentication with token generation.
- Created a simple HTTP router to handle API requests.
- Included JSON encoding/decoding utilities for API responses.
- Developed a script to launch the API server alongside darktable, ensuring seamless integration.
- Added necessary configuration and setup for the API server, including CORS support and error handling.
2026-06-10 15:02:19 -04:00

65 lines
1.5 KiB
Plaintext

meta {
name: Get Token
type: http
seq: 1
}
post {
url: {{baseUrl}}/oauth/token
body: form-urlencoded
auth: none
}
body:form-urlencoded {
grant_type: client_credentials
client_id: {{clientId}}
client_secret: {{clientSecret}}
}
script:post-response {
if (res.status === 200) {
bru.setVar("accessToken", res.body.access_token);
console.log("Token stored. Expires in", res.body.expires_in, "seconds.");
console.log("Scopes:", res.body.scope);
} else {
console.error("Token request failed:", res.status, res.body);
}
}
tests {
test("returns 200", function() {
expect(res.status).to.equal(200);
});
test("has access_token", function() {
expect(res.body.access_token).to.be.a("string");
expect(res.body.access_token.length).to.be.above(0);
});
test("token_type is Bearer", function() {
expect(res.body.token_type).to.equal("Bearer");
});
test("scope includes images:read", function() {
expect(res.body.scope).to.include("images:read");
});
test("scope includes cache:refresh", function() {
expect(res.body.scope).to.include("cache:refresh");
});
test("expires_in is 3600", function() {
expect(res.body.expires_in).to.equal(3600);
});
}
docs {
## OAuth 2.0 — Client Credentials Grant
Exchanges `client_id` + `client_secret` for a short-lived Bearer JWT.
The post-response script stores the token in `{{accessToken}}` so all
other requests pick it up automatically.
Run this request first before calling any protected endpoint.
}