Skip to content

Commit edf4f7d

Browse files
committed
refactor(auth): convert jwt auth to API-only (remove jwt passport strategy)
1 parent 634640f commit edf4f7d

File tree

8 files changed

+52
-62
lines changed

8 files changed

+52
-62
lines changed

config.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@
7878
"type": "object"
7979
}
8080
}
81+
},
82+
"apiAuthentication": {
83+
"description": "List of authentication sources for API endpoints. May be empty, in which case all endpoints are public.",
84+
"type": "array",
85+
"items": {
86+
"$ref": "#/definitions/authentication"
87+
}
8188
}
8289
},
8390
"definitions": {

package-lock.json

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"history": "5.3.0",
5454
"isomorphic-git": "^1.27.1",
5555
"jsonschema": "^1.4.1",
56+
"jsonwebtoken": "^9.0.2",
5657
"jwk-to-pem": "^2.0.7",
5758
"load-plugin": "^6.0.0",
5859
"lodash": "^4.17.21",
@@ -64,7 +65,6 @@
6465
"parse-diff": "^0.11.1",
6566
"passport": "^0.7.0",
6667
"passport-activedirectory": "^1.0.4",
67-
"passport-jwt": "^4.0.1",
6868
"passport-local": "^1.0.0",
6969
"perfect-scrollbar": "^1.5.5",
7070
"prop-types": "15.8.1",

proxy.config.json

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,19 @@
4949
"baseDN": "",
5050
"searchBase": ""
5151
}
52-
},
52+
},
5353
{
5454
"type": "openidconnect",
55-
"enabled": false,
55+
"enabled": true,
5656
"oidcConfig": {
57-
"issuer": "",
58-
"clientID": "",
59-
"clientSecret": "",
60-
"authorizationURL": "",
61-
"tokenURL": "",
62-
"userInfoURL": "",
63-
"callbackURL": "",
64-
"scope": ""
65-
}
66-
},
67-
{
68-
"type": "jwt",
69-
"enabled": false,
70-
"jwtConfig": {
71-
"clientID": "",
72-
"authorityURL": "",
73-
"expectedAudience": ""
57+
"issuer": "https://accounts.google.com",
58+
"clientID": "1009968223893-u92qq6itk7ej5008o4174gjubs5lhorg.apps.googleusercontent.com",
59+
"clientSecret": "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",
60+
"authorizationURL": "https://accounts.google.com/o/oauth2/auth",
61+
"tokenURL": "https://oauth2.googleapis.com/token",
62+
"userInfoURL": "https://openidconnect.googleapis.com/v1/userinfo",
63+
"callbackURL": "http://localhost:8080/api/auth/oidc/callback",
64+
"scope": "openid email profile"
7465
}
7566
}
7667
],
@@ -120,5 +111,15 @@
120111
"urlShortener": "",
121112
"contactEmail": "",
122113
"csrfProtection": true,
123-
"plugins": []
114+
"plugins": [],
115+
"apiAuthentication": [
116+
{
117+
"type": "jwt",
118+
"enabled": true,
119+
"jwtConfig": {
120+
"clientID": "1009968223893-u92qq6itk7ej5008o4174gjubs5lhorg.apps.googleusercontent.com",
121+
"authorityURL": "https://accounts.google.com"
122+
}
123+
}
124+
]
124125
}

src/config/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if (fs.existsSync(userSettingsPath)) {
1010
let _authorisedList = defaultSettings.authorisedList;
1111
let _database = defaultSettings.sink;
1212
let _authentication = defaultSettings.authentication;
13+
let _apiAuthentication = defaultSettings.apiAuthentication;
1314
let _tempPassword = defaultSettings.tempPassword;
1415
let _proxyUrl = defaultSettings.proxyUrl;
1516
let _api = defaultSettings.api;
@@ -88,6 +89,24 @@ const getAuthMethods = () => {
8889
return enabledAuthMethods;
8990
};
9091

92+
/**
93+
* Get the list of enabled authentication methods for API endpoints
94+
* @return {Array} List of enabled authentication methods
95+
*/
96+
const getAPIAuthMethods = () => {
97+
if (_userSettings !== null && _userSettings.apiAuthentication) {
98+
_apiAuthentication = _userSettings.apiAuthentication;
99+
}
100+
101+
const enabledAuthMethods = _apiAuthentication.filter(auth => auth.enabled);
102+
103+
if (enabledAuthMethods.length === 0) {
104+
throw new Error("No authentication method enabled.");
105+
}
106+
107+
return enabledAuthMethods;
108+
};
109+
91110
// Log configuration to console
92111
const logConfiguration = () => {
93112
console.log(`authorisedList = ${JSON.stringify(getAuthorisedList())}`);
@@ -205,6 +224,7 @@ exports.getAuthorisedList = getAuthorisedList;
205224
exports.getDatabase = getDatabase;
206225
exports.logConfiguration = logConfiguration;
207226
exports.getAuthMethods = getAuthMethods;
227+
exports.getAPIAuthMethods = getAPIAuthMethods;
208228
exports.getTempPasswordConfig = getTempPasswordConfig;
209229
exports.getCookieSecret = getCookieSecret;
210230
exports.getSessionMaxAgeHours = getSessionMaxAgeHours;

src/service/passport/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const passport = require("passport");
22
const local = require('./local');
33
const activeDirectory = require('./activeDirectory');
44
const oidc = require('./oidc');
5-
const jwt = require('./jwt');
65
const config = require('../../config');
76

87
// Allows obtaining strategy config function and type
@@ -11,7 +10,6 @@ const authStrategies = {
1110
local: local,
1211
activedirectory: activeDirectory,
1312
openidconnect: oidc,
14-
jwt: jwt,
1513
};
1614

1715
const configure = async () => {

src/service/passport/jwt.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/service/passport/jwtAuthHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ async function validateJwt(token, authorityUrl, clientID, expectedAudience) {
6565

6666
const jwtAuthHandler = () => {
6767
return async (req, res, next) => {
68-
const authMethods = require('../../config').getAuthMethods();
69-
const jwtAuthMethod = authMethods.find((method) => method.type.toLowerCase() === "jwt");
68+
const apiAuthMethods = require('../../config').getAPIAuthMethods();
69+
const jwtAuthMethod = apiAuthMethods.find((method) => method.type.toLowerCase() === "jwt");
7070
if (!jwtAuthMethod) {
7171
return next();
7272
}

0 commit comments

Comments
 (0)