Skip to content

Commit

Permalink
Move loadEnvs to Joi default functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Jan 24, 2020
1 parent 323a67d commit c88a5d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
20 changes: 9 additions & 11 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Joi = require('@hapi/joi');
const clone = require('clone');
const loadEnvs = require('./loadEnvs');
const getUser = require('./hooks/getUser');
const handleCallback = require('./hooks/handleCallback');

Expand All @@ -19,7 +18,7 @@ const paramsSchema = Joi.object({
Joi.string(),
Joi.array().items(Joi.string()),
Joi.boolean().valid(false)
]).required(),
]).required().default(() => process.env.APP_SESSION_SECRET),
auth0Logout: Joi.boolean().optional().default(false),
authorizationParams: Joi.object({
response_type: Joi.string().optional().default('id_token'),
Expand All @@ -33,20 +32,21 @@ const paramsSchema = Joi.object({
return responseIncludesTokens ? 'form_post' : undefined;
}),
}).optional().unknown(true).default(),
baseURL: Joi.string().uri().required(),
clientID: Joi.string().required(),
clientSecret: Joi.string().optional(),
baseURL: Joi.string().uri().required().default(() => process.env.BASE_URL),
clientID: Joi.string().required().default(() => process.env.CLIENT_ID),
clientSecret: Joi.string().optional().default(() => process.env.CLIENT_SECRET),
clockTolerance: Joi.number().optional().default(60),
errorOnRequiredAuth: Joi.boolean().optional().default(false),
getUser: Joi.function().optional().default(() => getUser),
handleCallback: Joi.function().optional().default(() => handleCallback),
httpOptions: Joi.object().optional(),
identityClaimFilter: Joi.array().optional().default(['aud', 'iss', 'iat', 'exp', 'nonce', 'azp', 'auth_time']),
idpLogout: Joi.boolean().optional().default(false).when(
'auth0Logout', { is: true, then: Joi.boolean().optional().default(true) }
),
idpLogout: Joi.boolean().optional().default((parent) => parent.auth0Logout || false),
idTokenAlg: Joi.string().not('none').optional().default('RS256'),
issuerBaseURL: Joi.alternatives([ Joi.string().uri(), Joi.string().hostname() ]).required(),
issuerBaseURL: Joi.alternatives([
Joi.string().uri(),
Joi.string().hostname()
]).required().default(() => process.env.ISSUER_BASE_URL),
legacySameSiteCookie: Joi.boolean().optional().default(true),
loginPath: Joi.string().uri({relativeOnly: true}).optional().default('/login'),
logoutPath: Joi.string().uri({relativeOnly: true}).optional().default('/logout'),
Expand All @@ -59,8 +59,6 @@ const paramsSchema = Joi.object({
module.exports.get = function(params) {
let config = typeof params == 'object' ? clone(params) : {};

loadEnvs(config);

const paramsValidation = paramsSchema.validate(config);

if(paramsValidation.error) {
Expand Down
16 changes: 0 additions & 16 deletions lib/loadEnvs.js

This file was deleted.

0 comments on commit c88a5d4

Please sign in to comment.