-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
43 lines (38 loc) · 1.28 KB
/
config.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
const simpleOauthModule = require("simple-oauth2");
const randomstring = require("randomstring");
const oauthProvider = process.env.OAUTH_PROVIDER || "github";
const loginAuthTarget = process.env.AUTH_TARGET || "_self";
const oauth2 = simpleOauthModule.create({
client: {
id: process.env.OAUTH_CLIENT_ID,
secret: process.env.OAUTH_CLIENT_SECRET
},
auth: {
// Supply GIT_HOSTNAME for enterprise github installs.
tokenHost: process.env.GIT_HOSTNAME || "https://github.com",
tokenPath: process.env.OAUTH_TOKEN_PATH || "/login/oauth/access_token",
authorizePath: process.env.OAUTH_AUTHORIZE_PATH || "/login/oauth/authorize"
}
});
const originPattern = process.env.ORIGIN || "";
if ("".match(originPattern)) {
console.warn(
"Insecure ORIGIN pattern used. This can give unauthorized users access to your repository."
);
if (process.env.NODE_ENV === "production") {
console.error("Will not run without a safe ORIGIN pattern in production.");
process.exit();
}
}
const authorizationUri = oauth2.authorizationCode.authorizeURL({
redirect_uri: process.env.REDIRECT_URL,
scope: process.env.SCOPES || "repo,user",
state: randomstring.generate(32)
});
module.exports = {
oauth2,
authorizationUri,
originPattern,
oauthProvider,
loginAuthTarget
};