Skip to content

Commit 7955e79

Browse files
authored
chore(SLB-453): publisher oauth updates (#1589)
* chore(SLB-453): add oauth configuration * chore(SLB-453): protect history routes with auth * fix(SLB-453): use the default access token expiration time * chore(SLB-453): set the session to 12h
1 parent 7bbeeed commit 7955e79

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

packages/npm/@amazeelabs/publisher/publisher.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ export default defineConfig({
1212
username: 'test',
1313
password: 'test',
1414
},
15+
// When several authentication methods are configured,
16+
// oAuth2 takes precedence.
17+
oAuth2: {
18+
clientId: process.env.OAUTH2_CLIENT_ID || 'publisher',
19+
clientSecret: process.env.OAUTH2_CLIENT_SECRET || 'publisher',
20+
// Applies for ResourceOwnerPassword only.
21+
scope: process.env.OAUTH2_SCOPE || 'publisher',
22+
tokenHost: process.env.OAUTH2_TOKEN_HOST || 'http://127.0.0.1:8888',
23+
tokenPath: process.env.OAUTH2_TOKEN_PATH || '/oauth/token',
24+
authorizePath:
25+
process.env.OAUTH2_AUTHORIZE_PATH ||
26+
'/oauth/authorize?response_type=code',
27+
sessionSecret: process.env.OAUTH2_SESSION_SECRET || 'banana',
28+
environmentType: process.env.OAUTH2_ENVIRONMENT_TYPE || 'development',
29+
grantType: 0, // AuthorizationCode
30+
},
1531
mode: 'local',
1632
commands: {
1733
clean:

packages/npm/@amazeelabs/publisher/src/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const runServer = async (): Promise<HttpTerminator> => {
137137
ws.on('close', sub.unsubscribe);
138138
});
139139

140+
app.use('/___status/history', authMiddleware);
140141
app.get('/___status/history', async (req, res) => {
141142
const { Build } = await getDatabase();
142143
const result = await Build.findAll({
@@ -145,6 +146,7 @@ const runServer = async (): Promise<HttpTerminator> => {
145146
res.json(result);
146147
});
147148

149+
app.use('/___status/history', authMiddleware);
148150
app.get('/___status/history/:id', async (req, res) => {
149151
const { Build } = await getDatabase();
150152
const result = await Build.findByPk(req.params.id);

packages/npm/@amazeelabs/publisher/src/tools/oAuth2.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ declare module 'express-session' {
2727
}
2828

2929
// In seconds
30-
export const SESSION_MAX_AGE = 300;
31-
export const ACCESS_TOKEN_EXPIRATION_TIME = 300;
30+
export const SESSION_MAX_AGE = 60 * 60 * 12;
3231

3332
const ENCRYPTION_KEY =
3433
process.env.ENCRYPTION_KEY || crypto.randomBytes(32).toString('hex');
@@ -319,7 +318,7 @@ export const isAuthenticated = async (req: Request): Promise<boolean> => {
319318
let result = false;
320319
let accessToken = getPersistedAccessToken(req);
321320
if (accessToken) {
322-
if (!accessToken.expired(ACCESS_TOKEN_EXPIRATION_TIME)) {
321+
if (!accessToken.expired()) {
323322
result = true;
324323
} else {
325324
try {

0 commit comments

Comments
 (0)