From 1a3fdc567de3fae13e74358d3ee78ce6e6dcbfb1 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Thu, 23 Apr 2020 13:59:45 +0200 Subject: [PATCH] added authorization --- oas/condition.yaml | 10 ++-- oas/material.yaml | 10 ++-- oas/measurement.yaml | 10 ++-- oas/model.yaml | 8 +-- oas/oas.yaml | 5 +- oas/others.yaml | 25 +++++++++ oas/sample.yaml | 14 +++-- oas/template.yaml | 24 ++++++--- oas/user.yaml | 17 +++--- package-lock.json | 18 +++++++ package.json | 4 ++ src/db.ts | 11 ++++ src/globals.ts | 2 +- src/helpers/authorize.ts | 100 ++++++++++++++++++++++++++++++++++++ src/index.ts | 16 ++++++ src/routes/root.spec.ts | 96 ++++++++++++++++++++++++++++++++-- src/routes/root.ts | 6 +++ src/routes/user.spec.ts | 45 +++++++++++++--- src/routes/user.ts | 3 ++ src/routes/validate/user.ts | 3 +- src/test/db.json | 13 ++++- 21 files changed, 393 insertions(+), 47 deletions(-) create mode 100644 src/helpers/authorize.ts diff --git a/oas/condition.yaml b/oas/condition.yaml index 1259ec1..cca8ca6 100644 --- a/oas/condition.yaml +++ b/oas/condition.yaml @@ -3,7 +3,7 @@ - $ref: 'oas.yaml#/components/parameters/Id' get: summary: TODO condition by id - description: 'levels: read, write, maintain, dev, admin' + description: 'Auth: all, levels: read, write, maintain, dev, admin' tags: - /condition responses: @@ -23,9 +23,11 @@ $ref: 'oas.yaml#/components/responses/500' put: summary: TODO add/change condition - description: 'levels: write, maintain, dev, admin' + description: 'Auth: basic, levels: write, maintain, dev, admin' tags: - /condition + security: + - BasicAuth: [] requestBody: required: true content: @@ -51,9 +53,11 @@ $ref: 'oas.yaml#/components/responses/500' delete: summary: TODO delete condition - description: 'levels: write, maintain, dev, admin' + description: 'Auth: basic, levels: write, maintain, dev, admin' tags: - /condition + security: + - BasicAuth: [] responses: 200: $ref: 'oas.yaml#/components/responses/Ok' diff --git a/oas/material.yaml b/oas/material.yaml index 2ba26d7..d5d7d34 100644 --- a/oas/material.yaml +++ b/oas/material.yaml @@ -3,7 +3,7 @@ - $ref: 'oas.yaml#/components/parameters/Id' get: summary: TODO get material details - description: 'levels: read, write, maintain, dev, admin' + description: 'Auth: all, levels: read, write, maintain, dev, admin' tags: - /material responses: @@ -21,9 +21,11 @@ $ref: 'oas.yaml#/components/responses/500' put: summary: TODO add/change material - description: 'levels: write, maintain, dev, admin' + description: 'Auth: basic, levels: write, maintain, dev, admin' tags: - /material + security: + - BasicAuth: [] requestBody: required: true content: @@ -47,9 +49,11 @@ $ref: 'oas.yaml#/components/responses/500' delete: summary: TODO delete material - description: 'levels: write, maintain, dev, admin' + description: 'Auth: basic, levels: write, maintain, dev, admin' tags: - /material + security: + - BasicAuth: [] responses: 200: $ref: 'oas.yaml#/components/responses/Ok' diff --git a/oas/measurement.yaml b/oas/measurement.yaml index 52c0430..0b4d5b2 100644 --- a/oas/measurement.yaml +++ b/oas/measurement.yaml @@ -3,7 +3,7 @@ - $ref: 'oas.yaml#/components/parameters/Id' get: summary: TODO measurement values by id - description: 'levels: read, write, maintain, dev, admin' + description: 'Auth: all, levels: read, write, maintain, dev, admin' tags: - /measurement responses: @@ -23,9 +23,11 @@ $ref: 'oas.yaml#/components/responses/500' put: summary: TODO add/change measurement - description: 'levels: write, maintain, dev, admin' + description: 'Auth: basic, levels: write, maintain, dev, admin' tags: - /measurement + security: + - BasicAuth: [] requestBody: required: true content: @@ -51,9 +53,11 @@ $ref: 'oas.yaml#/components/responses/500' delete: summary: TODO delete measurement - description: 'levels: write, maintain, dev, admin' + description: 'Auth: basic, levels: write, maintain, dev, admin' tags: - /measurement + security: + - BasicAuth: [] responses: 200: $ref: 'oas.yaml#/components/responses/Ok' diff --git a/oas/model.yaml b/oas/model.yaml index ce237e2..24df9af 100644 --- a/oas/model.yaml +++ b/oas/model.yaml @@ -3,7 +3,7 @@ - $ref: 'oas.yaml#/components/parameters/Name' get: summary: TODO get model data by name - description: 'levels: dev, admin' + description: 'Auth: all, levels: dev, admin' tags: - /model responses: @@ -24,7 +24,7 @@ $ref: 'oas.yaml#/components/responses/500' put: summary: TODO add/replace model data by name - description: 'levels: dev, admin' + description: 'Auth: all, levels: dev, admin' tags: - /model requestBody: @@ -50,9 +50,11 @@ $ref: 'oas.yaml#/components/responses/500' delete: summary: TODO delete model data - description: 'levels: dev, admin' + description: 'Auth: basic, levels: dev, admin' tags: - /model + security: + - BasicAuth: [] responses: 200: $ref: 'oas.yaml#/components/responses/Ok' diff --git a/oas/oas.yaml b/oas/oas.yaml index ba1bafd..03549c1 100644 --- a/oas/oas.yaml +++ b/oas/oas.yaml @@ -6,7 +6,10 @@ info: version: 1.0.0 description: | This API gives access to the project database.
- Access is restricted. Authentication can be obtained with HTTP Basic Auth using username and password. Data access methods can also be accessed using an API key at the URL ending like ?key=xxx
+ Access is restricted. Authentication can be obtained with HTTP Basic Auth using username and password. + Data access methods can also be accessed using an API key at the URL ending like ?key=xxx
+ The description lists available authentication methods, also the locks of each method close correspondingly + if the entered authentication is allowed.

There are a number of different user levels: