forked from okta/okta-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.js
49 lines (40 loc) · 1.61 KB
/
env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const PACKAGE = require('./package.json')
// Support storing environment variables in a file named "testenv"
const path = require('path')
const dotenv = require('dotenv')
const fs = require('fs')
// Read environment variables from "testenv". Override environment vars if they are already set.
const TESTENV = path.resolve(__dirname, 'testenv')
if (fs.existsSync(TESTENV)) {
const envConfig = dotenv.parse(fs.readFileSync(TESTENV))
Object.keys(envConfig).forEach((k) => {
process.env[k] = envConfig[k]
})
}
process.env.CLIENT_ID = process.env.CLIENT_ID || process.env.SPA_CLIENT_ID
module.exports = (overrides = {}) => {
const PORT = overrides.port || process.env.PORT || 3000
const BASE_URI = process.env.BASE_URI || `http://localhost:${PORT}`
const defaults = {
ISSUER: process.env.ISSUER || 'https://{yourOktaDomain}/oauth2/default',
USERNAME: process.env.USERNAME || '{username}',
PASSWORD: process.env.PASSWORD || '{password}',
OKTA_TESTING_DISABLEHTTPSCHECK: process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false,
BASE_URI,
PORT
}
const spaConstants = Object.assign({}, {
CLIENT_ID: process.env.SPA_CLIENT_ID || process.env.CLIENT_ID || '{clientId}',
REDIRECT_URI: `${BASE_URI}/implicit/callback`
}, defaults)
const webConstants = Object.assign({}, {
CLIENT_ID: process.env.WEB_CLIENT_ID || process.env.CLIENT_ID || '{clientId}',
CLIENT_SECRET: process.env.CLIENT_SECRET || '{clientSecret}',
APP_BASE_URL: BASE_URI
}, defaults)
const packageInfo = {
name: PACKAGE.name,
version: PACKAGE.version
}
return { spaConstants, webConstants, packageInfo }
}