Skip to content

Commit 979f6b2

Browse files
committed
Auth0 support added
1 parent 2667e38 commit 979f6b2

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

lib/openapi2schema.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ function buildPaths(paths, options, schemaOptions) {
9595
...rootParams
9696
}
9797
}
98+
if (methodStruct.security && methodStruct.security[0]['OAuth2']) {
99+
resultMethod.security = 'Auth0';
100+
}
98101
if (options.includeParameters && methodStruct.parameters) {
99102
for (let parameter of methodStruct.parameters) {
100103
console.log(parameter);

templates/fastify-server/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
"start": "node src/index.js"
99
},
1010
"dependencies": {
11-
"fastify": "^2.12.0",
12-
"fastify-cors": "^3.0.1",
11+
"fastify": "^2.12.1",
12+
"fastify-auth0-verify": "^0.2.0",
13+
"fastify-cors": "^3.0.2",
1314
"fastify-formbody": "^3.1.0",
14-
"fastify-multipart": "^1.0.4",
15-
"jsonfile": "^6.0.0",
15+
"fastify-multipart": "^1.0.5",
16+
"jsonfile": "^6.0.1",
1617
"ajv-oai": "^1.2.0"
1718
}
1819
}

templates/fastify-server/src/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import fastifyFormbody from 'fastify-formbody';
33
import fastifyMultipart from 'fastify-multipart';
44
import fastifyCors from 'fastify-cors';
55
import Ajv from "ajv-oai";
6+
{{#if @root.swagger.components.securitySchemes}}
7+
import fastifyAuth from 'fastify-auth0-verify';
8+
{{/if}}
69

710
const fastify = Fastify();
811

@@ -19,6 +22,12 @@ const options = { addToBody: true };
1922
fastify.register(fastifyFormbody);
2023
fastify.register(fastifyMultipart, options);
2124
fastify.register(fastifyCors, {});
25+
{{#if @root.swagger.components.securitySchemes}}
26+
fastify.register(fastifyAuth, {
27+
domain: process.env.AUTH_DOMAIN,
28+
audience: process.env.AUTH_SECRET,
29+
});
30+
{{/if}}
2231

2332
{{#each @root.swagger.endpoints}}
2433
{{#endsWith @root.swagger.basePath '/'}}

templates/fastify-server/src/routes/___.js.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default async function (fastify, opts) {
6363
{{/each}}
6464
*/
6565
let schema{{createName @key ../subresource}} = schemas['{{colonReplacer ../path_name}}']['{{@key}}'];
66-
fastify.{{@key}}('{{../subresource}}', { schema: schema{{createName @key ../subresource}} }, async (req, reply) => {
66+
fastify.{{@key}}('{{../subresource}}', { schema: schema{{createName @key ../subresource}}{{#if this.security}}, preValidation: fastify.authenticate{{/if}} }, async (req, reply) => {
6767
const options = {
6868
{{#if this.requestBody}}
6969
body: req.body{{#compare (lookup this.parameters 'length') 0 operator = '>' }},{{/compare}},

0 commit comments

Comments
 (0)