mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
support basic auth in ETAPI
This commit is contained in:
parent
6d4ef4ee3d
commit
3e4a9f63fa
@ -15,6 +15,7 @@ servers:
|
|||||||
- url: http://localhost:8080/etapi
|
- url: http://localhost:8080/etapi
|
||||||
security:
|
security:
|
||||||
- EtapiTokenAuth: []
|
- EtapiTokenAuth: []
|
||||||
|
- EtapiBasicAuth: []
|
||||||
paths:
|
paths:
|
||||||
/create-note:
|
/create-note:
|
||||||
post:
|
post:
|
||||||
@ -677,6 +678,14 @@ components:
|
|||||||
type: apiKey
|
type: apiKey
|
||||||
in: header
|
in: header
|
||||||
name: Authorization
|
name: 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:
|
schemas:
|
||||||
CreateNoteDef:
|
CreateNoteDef:
|
||||||
type: object
|
type: object
|
||||||
|
@ -30,6 +30,20 @@ function parseAuthToken(auth) {
|
|||||||
return null;
|
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("_");
|
const chunks = auth.split("_");
|
||||||
|
|
||||||
if (chunks.length === 1) {
|
if (chunks.length === 1) {
|
||||||
|
@ -3,5 +3,5 @@ Authorization: {{authToken}}
|
|||||||
|
|
||||||
> {%
|
> {%
|
||||||
client.assert(response.status === 200);
|
client.assert(response.status === 200);
|
||||||
client.assert(response.body == "Hi there!");
|
client.assert(response.body.clipperProtocolVersion === "1.0");
|
||||||
%}
|
%}
|
||||||
|
14
test-etapi/basic-auth.http
Normal file
14
test-etapi/basic-auth.http
Normal file
@ -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); %}
|
Loading…
x
Reference in New Issue
Block a user