Skip to content

Commit 267e8fe

Browse files
committed
feat: added OpenID integration
1 parent 3ad21f3 commit 267e8fe

5 files changed

Lines changed: 61 additions & 2 deletions

File tree

docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ services:
1313
JWT_EXPIRATION: "${JWT_EXPIRATION}"
1414
JWT_ISSUER: "${JWT_ISSUER}"
1515
JWT_MAX_AGE: "${JWT_MAX_AGE}"
16+
OPENID_ID: "${OPENID_ID}"
17+
OPENID_SECRET: "${OPENID_SECRET}"
18+
OPENID_REDIRECT: "${OPENID_REDIRECT}"
19+
OPENID_WELL_KNOWN: "${OPENID_WELL_KNOWN}"
1620
links:
1721
- database
1822
restart: unless-stopped

docs/CONFIGURATION.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ The following configuration items can be set using environment variables, note t
2020
| JWT_EXPIRATION | Token expiration time as time literal. | 1d |
2121
| JWT_ISSUER | Identifies principal that issued the JWT. | o2-ui |
2222
| JWT_MAX_AGE | Token refresh expiration time as time literal. | 7d |
23+
24+
## OpenID
25+
| Variable name | Description | Default value |
26+
|---------------|-------------|---------------|
27+
| OPENID_ID | Application ID | |
28+
| OPENID_SECRET | Application secret | |
29+
| OPENID_REDIRECT | Authentication callback | |
30+
| OPENID_WELL_KNOWN | So-called "well-known" endpoint defining OpenID configuration. | https://auth.cern.ch/auth/realms/cern/.well-known/openid-configuration |

lib/config/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
const database = require('./database');
1515
const jwt = require('./jwt');
16+
const openId = require('./openid');
1617

1718
module.exports = {
1819
DatabaseConfig: database,
1920
JwtConfig: jwt,
21+
OpenIdConfig: openId,
2022
};

lib/config/openid.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
let secret = null;
15+
let id = null;
16+
let redirect_uri = null;
17+
let well_known = 'https://auth.cern.ch/auth/realms/cern/.well-known/openid-configuration';
18+
19+
if (process.env.OPENID_SECRET) {
20+
secret = process.env.OPENID_SECRET;
21+
}
22+
23+
if (process.env.OPENID_ID) {
24+
id = process.env.OPENID_ID;
25+
}
26+
27+
if (process.env.OPENID_REDIRECT) {
28+
redirect_uri = process.env.OPENID_REDIRECT;
29+
}
30+
31+
if (process.env.OPENID_WELL_KNOWN) {
32+
well_known = process.env.OPENID_WELL_KNOWN;
33+
}
34+
35+
module.exports = {
36+
secret,
37+
id,
38+
redirect_uri,
39+
well_known: well_known,
40+
isValid: () => secret !== null && id !== null && redirect_uri !== null && well_known !== null,
41+
};

lib/server/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
const path = require('path');
1515
const { HttpServer } = require('@aliceo2/web-ui');
1616
const buildEndpoints = require('./routers');
17-
const { JwtConfig } = require('../config');
17+
const { JwtConfig, OpenIdConfig } = require('../config');
1818
const { Logger } = require('../utilities');
1919

2020
/**
@@ -27,10 +27,14 @@ class WebUiServer {
2727
constructor() {
2828
this.logger = Logger('HTTP');
2929

30+
if (!OpenIdConfig.isValid()) {
31+
this.logger.info('Missing OpenID configuration');
32+
}
33+
3034
this.http = new HttpServer({
3135
port: 4000,
3236
autoListen: false,
33-
}, JwtConfig);
37+
}, JwtConfig, OpenIdConfig.isValid() ? OpenIdConfig : null);
3438

3539
this.http.addStaticPath(path.resolve(__dirname, '..', 'public'));
3640
buildEndpoints(this.http);

0 commit comments

Comments
 (0)