Skip to content

Commit

Permalink
Merge pull request #157 from trojs/feature/remove-default-auth
Browse files Browse the repository at this point in the history
Remove default auth method
  • Loading branch information
w3nl authored Oct 1, 2024
2 parents 1c8f78e + 8672eb8 commit cc7757a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const api = new Api({
version: 'v1',
specification: openAPISpecification,
controllers,
secret: 'test',
logger: console,
ajvOptions: { allErrors: true }
})
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@trojs/openapi-server",
"description": "OpenAPI Server",
"version": "2.0.4",
"version": "2.0.5",
"author": {
"name": "Pieter Wigboldus",
"url": "https://trojs.org/"
Expand Down
4 changes: 0 additions & 4 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { setupRouter } from './router.js';
* @property {string} version
* @property {object} specification
* @property {object} controllers
* @property {string=} secret
* @property {string=} apiRoot
* @property {boolean=} strictSpecification
* @property {boolean=} errorDetails
Expand All @@ -43,7 +42,6 @@ export class Api {
version,
specification,
controllers,
secret,
apiRoot,
strictSpecification,
errorDetails,
Expand All @@ -57,7 +55,6 @@ export class Api {
this.version = version;
this.specification = specification;
this.controllers = controllers;
this.secret = secret;
this.apiRoot = apiRoot;
this.strictSpecification = strictSpecification;
this.errorDetails = errorDetails || false;
Expand Down Expand Up @@ -86,7 +83,6 @@ export class Api {
}

const { api } = setupRouter({
secret: this.secret,
openAPISpecification: this.specification,
controllers: this.controllers,
apiRoot: this.apiRoot,
Expand Down
9 changes: 0 additions & 9 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { unauthorized } from './handlers/unauthorized.js';
/**
* Setup the router
* @param {object} params
* @param {string=} params.secret
* @param {object} params.openAPISpecification
* @param {object} params.controllers
* @param {string=} params.apiRoot
Expand All @@ -29,7 +28,6 @@ import { unauthorized } from './handlers/unauthorized.js';
* @returns {{ api: OpenAPIBackend<any>, openAPISpecification: object }}
*/
export const setupRouter = ({
secret,
openAPISpecification,
controllers,
apiRoot,
Expand Down Expand Up @@ -83,13 +81,6 @@ export const setupRouter = ({
return mock;
});

if (secret) {
api.registerSecurityHandler(
'apiKey',
(context) => context.request.headers['x-api-key'] === secret
);
}

securityHandlers.forEach((securityHandler) => {
api.registerSecurityHandler(
securityHandler.name,
Expand Down
5 changes: 5 additions & 0 deletions src/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ function customHandler(context) {
}

const securityHandlers = [
{
name: 'apiKey',
handler: (context) =>
context.request.headers['x-api-key'] === envExample.SECRET,
},
{
name: 'customSecurityHandler',
handler: customHandler,
Expand Down

0 comments on commit cc7757a

Please sign in to comment.