Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
support basic auth in ETAPI
zadam3e4a9f63fa1f
diff --git a/src/etapi/etapi.openapi.yaml b/src/etapi/etapi.openapi.yamlindex 82177d4289..497b62c5a5 100644--- a/src/etapi/etapi.openapi.yaml+++ b/src/etapi/etapi.openapi.yaml@@ -15,6 +15,7 @@ servers:- url: http://localhost:8080/etapisecurity:- EtapiTokenAuth: []+ - EtapiBasicAuth: []paths:/create-note:post:@@ -677,6 +678,14 @@ components:type: apiKeyin: headername: Authorization+ EtapiBasicAuth:+ type: http+ scheme: basic+ description: >+ Basic Auth where username is arbitrary string (e.g. "trilium", not checked),+ username is the ETAPI token.+ To emphasize, do not use Trilium password here (won't work), only the generated+ ETAPI token (from Options -> ETAPI)schemas:CreateNoteDef:type: objectdiff --git a/src/services/etapi_tokens.js b/src/services/etapi_tokens.jsindex 6b4ec62772..d56c31bd99 100644--- a/src/services/etapi_tokens.js+++ b/src/services/etapi_tokens.js@@ -30,6 +30,20 @@ function parseAuthToken(auth) {return null;}+ if (auth.startsWith("Basic ")) {+ // allow also basic auth format for systems which allow this type of authentication+ // expect ETAPI token in the password field, ignore username+ // https://github.com/zadam/trilium/issues/3181+ const basicAuthStr = utils.fromBase64(auth.substring(6)).toString("UTF-8");+ const basicAuthChunks = basicAuthStr.split(":");++ if (basicAuthChunks.length === 2) {+ auth = basicAuthChunks[1];+ } else {+ return null;+ }+ }+const chunks = auth.split("_");if (chunks.length === 1) {diff --git a/test-etapi/app-info.http b/test-etapi/app-info.httpindex 5945a07b13..a851005c24 100644--- a/test-etapi/app-info.http+++ b/test-etapi/app-info.http@@ -3,5 +3,5 @@ Authorization: {{authToken}}> {%client.assert(response.status === 200);- client.assert(response.body == "Hi there!");+ client.assert(response.body.clipperProtocolVersion === "1.0");%}diff --git a/test-etapi/basic-auth.http b/test-etapi/basic-auth.httpnew file mode 100644index 0000000000..88c76b7c24--- /dev/null+++ b/test-etapi/basic-auth.http@@ -0,0 +1,14 @@+GET {{triliumHost}}/etapi/app-info+Authorization: Basic whatever {{authToken}}++> {%+ client.assert(response.status === 200);+ client.assert(response.body.clipperProtocolVersion === "1.0");+%}++###++GET {{triliumHost}}/etapi/app-info+Authorization: Basic whatever wrong pass++> {% client.assert(response.status === 401); %}