Skip to content

Instantly share code, notes, and snippets.

@jomaora
Last active February 14, 2019 16:54
Show Gist options
  • Save jomaora/49837b02ecf6382c7aa4b1fee85d3e63 to your computer and use it in GitHub Desktop.
Save jomaora/49837b02ecf6382c7aa4b1fee85d3e63 to your computer and use it in GitHub Desktop.
const sessionAuthenticator = ({jwt: config}) => async (pluginContext, info) => {
try {
const params = await pluginContext.getParams();
const apiToken = _.get('authorization', pluginContext.req.headers);
// Business logic for authorization
return {type: 'success', user: pluginContext.req.user};
} catch (err) {
return {type: 'invalid', statusCode: 401, message: 'Invalid or missing authorization key'};
}
};
const exegesisMiddleware = await exegesisExpress.middleware(
path.resolve(__dirname, '../openapi.yaml'),
{
controllers: path.resolve(__dirname, './controllers'),
authenticators: {
token: sessionAuthenticator(config)
}
}
);
app.use(exegesisMiddleware);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment