Skip to content

Commit 7e36e21

Browse files
committed
chore: prettier
1 parent a9b5810 commit 7e36e21

File tree

19 files changed

+325
-388
lines changed

19 files changed

+325
-388
lines changed

src/config/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const getDatabase = () => {
9292

9393
/**
9494
* Get the list of enabled authentication methods
95-
*
95+
*
9696
* At least one authentication method must be enabled.
9797
* @return {Array} List of enabled authentication methods
9898
*/
@@ -104,15 +104,15 @@ export const getAuthMethods = () => {
104104
const enabledAuthMethods = _authentication.filter((auth) => auth.enabled);
105105

106106
if (enabledAuthMethods.length === 0) {
107-
throw new Error("No authentication method enabled");
107+
throw new Error('No authentication method enabled');
108108
}
109109

110110
return enabledAuthMethods;
111111
};
112112

113113
/**
114114
* Get the list of enabled authentication methods for API endpoints
115-
*
115+
*
116116
* If no API authentication methods are enabled, all endpoints are public.
117117
* @return {Array} List of enabled authentication methods
118118
*/
@@ -121,7 +121,7 @@ export const getAPIAuthMethods = () => {
121121
_apiAuthentication = _userSettings.apiAuthentication;
122122
}
123123

124-
const enabledAuthMethods = _apiAuthentication.filter(auth => auth.enabled);
124+
const enabledAuthMethods = _apiAuthentication.filter((auth) => auth.enabled);
125125

126126
return enabledAuthMethods;
127127
};

src/proxy/processors/push-action/parsePush.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function exec(req: any, action: Action): Promise<Action> {
3535
action.commitFrom = action.commitData[action.commitData.length - 1].parent;
3636
}
3737

38-
const {committer, committerEmail} = action.commitData[action.commitData.length - 1];
38+
const { committer, committerEmail } = action.commitData[action.commitData.length - 1];
3939
console.log(`Push Request received from user ${committer} with email ${committerEmail}`);
4040
action.user = committer;
4141
action.userEmail = committerEmail;
@@ -123,7 +123,7 @@ const getCommitData = (contents: CommitContent[]) => {
123123
commitTimestamp,
124124
message,
125125
authorEmail,
126-
committerEmail
126+
committerEmail,
127127
});
128128

129129
if (
@@ -146,7 +146,7 @@ const getCommitData = (contents: CommitContent[]) => {
146146
commitTimestamp,
147147
message,
148148
authorEmail,
149-
committerEmail
149+
committerEmail,
150150
};
151151
})
152152
.value();

src/routes.jsx

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,83 +35,65 @@ const dashboardRoutes = [
3535
path: '/repo',
3636
name: 'Repositories',
3737
icon: RepoIcon,
38-
component: (props) =>
39-
<RouteGuard
40-
component={RepoList}
41-
fullRoutePath={`/dashboard/repo`}
42-
/>,
38+
component: (props) => <RouteGuard component={RepoList} fullRoutePath={`/dashboard/repo`} />,
4339
layout: '/dashboard',
4440
visible: true,
4541
},
4642
{
4743
path: '/repo/:id',
4844
name: 'Repo Details',
4945
icon: Person,
50-
component: (props) =>
51-
<RouteGuard
52-
component={RepoDetails}
53-
fullRoutePath={`/dashboard/repo/:id`}
54-
/>,
46+
component: (props) => (
47+
<RouteGuard component={RepoDetails} fullRoutePath={`/dashboard/repo/:id`} />
48+
),
5549
layout: '/dashboard',
5650
visible: false,
5751
},
5852
{
5953
path: '/push',
6054
name: 'Dashboard',
6155
icon: Dashboard,
62-
component: (props) =>
63-
<RouteGuard
64-
component={OpenPushRequests}
65-
fullRoutePath={`/dashboard/push`}
66-
/>,
56+
component: (props) => (
57+
<RouteGuard component={OpenPushRequests} fullRoutePath={`/dashboard/push`} />
58+
),
6759
layout: '/dashboard',
6860
visible: true,
6961
},
7062
{
7163
path: '/push/:id',
7264
name: 'Open Push Requests',
7365
icon: Person,
74-
component: (props) =>
75-
<RouteGuard
76-
component={PushDetails}
77-
fullRoutePath={`/dashboard/push/:id`}
78-
/>,
66+
component: (props) => (
67+
<RouteGuard component={PushDetails} fullRoutePath={`/dashboard/push/:id`} />
68+
),
7969
layout: '/dashboard',
8070
visible: false,
8171
},
8272
{
8373
path: '/profile',
8474
name: 'My Account',
8575
icon: AccountCircle,
86-
component: (props) =>
87-
<RouteGuard
88-
component={User}
89-
fullRoutePath={`/dashboard/profile`}
90-
/>,
76+
component: (props) => <RouteGuard component={User} fullRoutePath={`/dashboard/profile`} />,
9177
layout: '/dashboard',
9278
visible: true,
9379
},
9480
{
9581
path: '/admin/user',
9682
name: 'Users',
9783
icon: Group,
98-
component: (props) =>
99-
<RouteGuard
100-
component={UserList}
101-
fullRoutePath={`/dashboard/admin/user`}
102-
/>,
84+
component: (props) => (
85+
<RouteGuard component={UserList} fullRoutePath={`/dashboard/admin/user`} />
86+
),
10387
layout: '/dashboard',
10488
visible: true,
10589
},
10690
{
10791
path: '/admin/user/:id',
10892
name: 'User',
10993
icon: Person,
110-
component: (props) =>
111-
<RouteGuard
112-
component={User}
113-
fullRoutePath={`/dashboard/admin/user/:id`}
114-
/>,
94+
component: (props) => (
95+
<RouteGuard component={User} fullRoutePath={`/dashboard/admin/user/:id`} />
96+
),
11597
layout: '/dashboard',
11698
visible: false,
11799
},

src/service/passport/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const passport = require("passport");
1+
const passport = require('passport');
22
const local = require('./local');
33
const activeDirectory = require('./activeDirectory');
44
const oidc = require('./oidc');
@@ -20,12 +20,12 @@ const configure = async () => {
2020

2121
for (const auth of authMethods) {
2222
const strategy = authStrategies[auth.type.toLowerCase()];
23-
if (strategy && typeof strategy.configure === "function") {
23+
if (strategy && typeof strategy.configure === 'function') {
2424
await strategy.configure(passport);
2525
}
2626
}
2727

28-
if (authMethods.some(auth => auth.type.toLowerCase() === "local")) {
28+
if (authMethods.some((auth) => auth.type.toLowerCase() === 'local')) {
2929
await local.createDefaultAdmin();
3030
}
3131

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const axios = require("axios");
2-
const jwt = require("jsonwebtoken");
3-
const jwkToPem = require("jwk-to-pem");
1+
const axios = require('axios');
2+
const jwt = require('jsonwebtoken');
3+
const jwkToPem = require('jwk-to-pem');
44
const config = require('../../config');
55

66
/**
@@ -10,97 +10,102 @@ const config = require('../../config');
1010
*/
1111
async function getJwks(authorityUrl) {
1212
try {
13-
const { data } = await axios.get(`${authorityUrl}/.well-known/openid-configuration`);
14-
const jwksUri = data.jwks_uri;
13+
const { data } = await axios.get(`${authorityUrl}/.well-known/openid-configuration`);
14+
const jwksUri = data.jwks_uri;
1515

16-
const { data: jwks } = await axios.get(jwksUri);
17-
return jwks.keys;
16+
const { data: jwks } = await axios.get(jwksUri);
17+
return jwks.keys;
1818
} catch (error) {
19-
console.error("Error fetching JWKS:", error);
20-
throw new Error("Failed to fetch JWKS");
19+
console.error('Error fetching JWKS:', error);
20+
throw new Error('Failed to fetch JWKS');
2121
}
2222
}
2323

2424
/**
2525
* Validate a JWT token using the OIDC configuration.
2626
* @param {*} token the JWT token
2727
* @param {*} authorityUrl the OIDC authority URL
28-
* @param {*} clientID the OIDC client ID
28+
* @param {*} clientID the OIDC client ID
2929
* @param {*} expectedAudience the expected audience for the token
3030
* @return {Promise<object>} the verified payload or an error
3131
*/
3232
async function validateJwt(token, authorityUrl, clientID, expectedAudience) {
3333
try {
34-
const jwks = await getJwks(authorityUrl);
34+
const jwks = await getJwks(authorityUrl);
3535

36-
const decodedHeader = await jwt.decode(token, { complete: true });
37-
if (!decodedHeader || !decodedHeader.header || !decodedHeader.header.kid) {
38-
throw new Error("Invalid JWT: Missing key ID (kid)");
39-
}
36+
const decodedHeader = await jwt.decode(token, { complete: true });
37+
if (!decodedHeader || !decodedHeader.header || !decodedHeader.header.kid) {
38+
throw new Error('Invalid JWT: Missing key ID (kid)');
39+
}
4040

41-
const { kid } = decodedHeader.header;
42-
const jwk = jwks.find((key) => key.kid === kid);
43-
if (!jwk) {
44-
throw new Error("No matching key found in JWKS");
45-
}
41+
const { kid } = decodedHeader.header;
42+
const jwk = jwks.find((key) => key.kid === kid);
43+
if (!jwk) {
44+
throw new Error('No matching key found in JWKS');
45+
}
4646

47-
const pubKey = jwkToPem(jwk);
47+
const pubKey = jwkToPem(jwk);
4848

49-
const verifiedPayload = jwt.verify(token, pubKey, {
50-
algorithms: ["RS256"],
51-
issuer: authorityUrl,
52-
audience: expectedAudience,
53-
});
49+
const verifiedPayload = jwt.verify(token, pubKey, {
50+
algorithms: ['RS256'],
51+
issuer: authorityUrl,
52+
audience: expectedAudience,
53+
});
5454

55-
if (verifiedPayload.azp !== clientID) {
56-
throw new Error("JWT client ID does not match");
57-
}
55+
if (verifiedPayload.azp !== clientID) {
56+
throw new Error('JWT client ID does not match');
57+
}
5858

59-
return { verifiedPayload };
59+
return { verifiedPayload };
6060
} catch (error) {
61-
const errorMessage = `JWT validation failed: ${error.message}\n`;
62-
console.error(errorMessage);
63-
return { error: errorMessage };
61+
const errorMessage = `JWT validation failed: ${error.message}\n`;
62+
console.error(errorMessage);
63+
return { error: errorMessage };
6464
}
6565
}
6666

6767
const jwtAuthHandler = () => {
6868
return async (req, res, next) => {
6969
const apiAuthMethods = config.getAPIAuthMethods();
70-
const jwtAuthMethod = apiAuthMethods.find((method) => method.type.toLowerCase() === "jwt");
71-
if (!jwtAuthMethod) {
72-
return next();
73-
}
74-
75-
if (req.isAuthenticated()) {
76-
return next();
77-
}
78-
79-
const token = req.header("Authorization");
80-
if (!token) {
81-
return res.status(401).send("No token provided\n");
82-
}
83-
84-
const { clientID, authorityURL, expectedAudience } = jwtAuthMethod.jwtConfig;
85-
const audience = expectedAudience || clientID;
86-
87-
if (!authorityURL) {
88-
return res.status(500).send("OIDC authority URL is not configured\n");
89-
}
90-
91-
if (!clientID) {
92-
return res.status(500).send("OIDC client ID is not configured\n");
93-
}
94-
95-
const tokenParts = token.split(" ");
96-
const { verifiedPayload, error } = await validateJwt(tokenParts[1], authorityURL, audience, clientID);
97-
if (error) {
98-
return res.status(401).send(error);
99-
}
100-
101-
req.user = verifiedPayload;
70+
const jwtAuthMethod = apiAuthMethods.find((method) => method.type.toLowerCase() === 'jwt');
71+
if (!jwtAuthMethod) {
10272
return next();
103-
}
104-
}
73+
}
74+
75+
if (req.isAuthenticated()) {
76+
return next();
77+
}
78+
79+
const token = req.header('Authorization');
80+
if (!token) {
81+
return res.status(401).send('No token provided\n');
82+
}
83+
84+
const { clientID, authorityURL, expectedAudience } = jwtAuthMethod.jwtConfig;
85+
const audience = expectedAudience || clientID;
86+
87+
if (!authorityURL) {
88+
return res.status(500).send('OIDC authority URL is not configured\n');
89+
}
90+
91+
if (!clientID) {
92+
return res.status(500).send('OIDC client ID is not configured\n');
93+
}
94+
95+
const tokenParts = token.split(' ');
96+
const { verifiedPayload, error } = await validateJwt(
97+
tokenParts[1],
98+
authorityURL,
99+
audience,
100+
clientID,
101+
);
102+
if (error) {
103+
return res.status(401).send(error);
104+
}
105+
106+
req.user = verifiedPayload;
107+
return next();
108+
};
109+
};
105110

106111
module.exports = jwtAuthHandler;

0 commit comments

Comments
 (0)