Skip to content

KTH/kth-node-api-key-strategy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a08368e · Feb 12, 2025

History

72 Commits
Feb 12, 2025
Aug 2, 2024
Apr 16, 2021
Dec 10, 2021
Apr 16, 2021
Nov 28, 2023
Aug 31, 2016
Sep 30, 2019
Nov 28, 2023
Dec 10, 2021
Dec 10, 2021
Jan 28, 2025
Aug 2, 2024

Repository files navigation

kth-node-api-key-strategy Build Status

A api key strategy for Node applications.

Configure

serverSettings.js

module.exports = {
  secure: {
    api_keys: [
      {name: 'devClient', apikey: '1234567', scope: ['write', 'read']},
      {name: 'testClient', apikey: '891011', scope: ['read']}
      {name: 'publicClient', apikey: '0000', scope: ['readPublic']}
    ],
  }
};

swagger.js

Setting security on a route

"/v1/some/route/{id}": {
      "get": {
        "operationId": "",
        "summary": "",
        "description": "",
        "parameters": [],
        "tags": [
          "v1"
        ],
        "responses": { ... },
        "security": {
          "api_key": [
            "read"
          ]
        }
      }
    }

Defining security definition

"securityDefinitions": {
    "api_key": {
      "type": "apiKey",
      "name": "api_key",
      "in": "header",
      "scopes": {
        "read": "Read access to data",
        "write": "Write access to data",
        "readPublic": "Read only access to publicly visible data",
      }
    }
  }