From fcc5214238e7dbf7279ed4fb1c2f491642bfafff Mon Sep 17 00:00:00 2001 From: Benjamin Fan Date: Fri, 30 Aug 2024 14:35:08 -0700 Subject: [PATCH] fix(docs): Add/update API keys list --- .../dev/reference/backend/apikeys/list/en.md | 62 +++++++++++++++++++ sites/backend/openapi/apikeys.mjs | 11 +--- 2 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 markdown/dev/reference/backend/apikeys/list/en.md diff --git a/markdown/dev/reference/backend/apikeys/list/en.md b/markdown/dev/reference/backend/apikeys/list/en.md new file mode 100644 index 00000000000..d31bbd3df14 --- /dev/null +++ b/markdown/dev/reference/backend/apikeys/list/en.md @@ -0,0 +1,62 @@ +--- +title: List API keys +--- + +Lists existing API keys. + +## Access control + +- [Permission level](/reference/backend/rbac) `0` or higher is required to list API keys + +## Endpoints + +Listing API keys is possible via these endpoints: + +| Method | Path | Authentication | +| --------: | :--- | :------------- | +| | `/apikeys/jwt` | [JSON Web Token](/reference/backend/authentication#jwt-authentication) | +| | `/apikeys/key` | [API Key & Secret](/reference/backend/authentication#key-authentication) | + +## Response status codes + +Possible status codes for these endpoints are: + +| Status code | Description | +| ----------: | :---------- | +| | success | +| | API key not found | + +## Response body + +| Value | Type | Description | +| ------------------- | -------- | ----------- | +| `result` | `string` | `success` on success, and `error` on error | +| `error` | `string` | Will give info on the nature of the error. Only set if an error occurred. | +| `apikeys` | `Array`` | Array of API key strings | + +## Example request + +```js +const keyInfo = await axios.get( + 'https://backend.freesewing.org/apikeys/jwt', + { + headers: { + Authorization: `Bearer ${token}` + } + } +) +``` + +## Example response +```200.json +{ + "result": "success", + "apikeys": { + [ + "7ea12968-7758-40b6-8c73-75cc99be762b", + "7ea12968-7758-40b6-8c73-39bc3b6707a9", + "7ea12968-7758-40b6-8c73-97bb9901010d", + ], + } +} +``` diff --git a/sites/backend/openapi/apikeys.mjs b/sites/backend/openapi/apikeys.mjs index bd599d92f64..9912ca3fcdd 100644 --- a/sites/backend/openapi/apikeys.mjs +++ b/sites/backend/openapi/apikeys.mjs @@ -32,7 +32,7 @@ delete local.response.body.regular.properties.secret // Paths export const paths = {} -// Create API key +// List API keys or Create an API key paths['/apikeys/{auth}'] = { get: { ...common, @@ -55,14 +55,7 @@ paths['/apikeys/{auth}'] = { }, }), }, - 401: response.status['401'], - 403: { - ...response.status['403'], - description: - response.status['403'].description + - errorExamples(['accountStatusLacking', 'insufficientAccessLevel']), - }, - 500: response.status['500'], + 404: response.status['404'], }, }, post: {