Skip to content

Commit d7e38cb

Browse files
committed
Merge branch 'rophy/oidc' into develop
2 parents 22d07fe + 5d6b436 commit d7e38cb

12 files changed

Lines changed: 324 additions & 4 deletions

File tree

.example.env

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ DISALLOW_REGISTRATION=true
5858
# Optional - Disable anonymous link creation. Default is true.
5959
DISALLOW_ANONYMOUS_LINKS=true
6060

61+
6162
# Optional - This would be shown to the user on the settings page
6263
# It's only for display purposes and has no other use
6364
SERVER_IP_ADDRESS=
@@ -87,3 +88,15 @@ REPORT_EMAIL=
8788

8889
# Optional - Support email to show on the app
8990
CONTACT_EMAIL=
91+
92+
# Optional - Login with OIDC
93+
OIDC_ENABLED=false
94+
OIDC_ISSUER=
95+
OIDC_CLIENT_ID=
96+
OIDC_CLIENT_SECRET=
97+
OIDC_SCOPE=
98+
OIDC_EMAIL_CLAIM=
99+
OIDC_APP_URL=
100+
101+
# Optional - Disable form-based login. Only makes sense when OIDC_ENABLED=true.
102+
DISALLOW_FORM_LOGIN=false

docker-compose.oidc.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
services:
2+
server:
3+
build:
4+
context: .
5+
volumes:
6+
- db_data_sqlite:/var/lib/kutt
7+
- custom:/kutt/custom
8+
env_file: .env
9+
environment:
10+
DB_FILENAME: "/var/lib/kutt/data.sqlite"
11+
DISALLOW_REGISTRATION: "false"
12+
OIDC_ENABLED: "true"
13+
OIDC_ISSUER: http://7f000101.nip.io:8080
14+
OIDC_CLIENT_ID: mock-client-id
15+
OIDC_CLIENT_SECRET: some-client-Secret
16+
OIDC_SCOPE: openid profile email
17+
OIDC_APP_URL: http://localhost:3000
18+
ports:
19+
- 3000:3000
20+
links:
21+
- oidc-server-mock:7f000101.nip.io
22+
oidc-server-mock:
23+
container_name: oidc-server-mock
24+
image: ghcr.io/soluto/oidc-server-mock:0.11.0
25+
ports:
26+
- 8080:8080
27+
domainname: 7f000101.nip.io
28+
environment:
29+
SERVER_OPTIONS_INLINE: |
30+
{
31+
"AccessTokenJwtType": "JWT",
32+
"Discovery": {
33+
"ShowKeySet": true
34+
},
35+
"Authentication": {
36+
"CookieSameSiteMode": "Lax",
37+
"CheckSessionCookieSameSiteMode": "Lax"
38+
}
39+
}
40+
CLIENTS_CONFIGURATION_INLINE: |
41+
[
42+
{
43+
"ClientId": "mock-client-id",
44+
"ClientSecrets": ["some-client-Secret"],
45+
"Description": "Mock OIDC",
46+
"AllowedGrantTypes": ["authorization_code"],
47+
"AllowAccessTokensViaBrowser": true,
48+
"RedirectUris": ["http://localhost:3000/*"],
49+
"AllowedScopes": ["openid", "profile", "email"],
50+
"IdentityTokenLifetime": 3600,
51+
"AccessTokenLifetime": 3600
52+
}
53+
]
54+
USERS_CONFIGURATION_INLINE: |
55+
[
56+
{
57+
"SubjectId":"1",
58+
"Username":"user01",
59+
"Password":"pwd",
60+
"Claims": [
61+
{ "Type": "name", "Value": "User 01", "ValueType": "string" },
62+
{ "Type": "email", "Value": "user01@example.localhost", "ValueType": "string" }
63+
],
64+
},
65+
{
66+
"SubjectId":"2",
67+
"Username":"user02",
68+
"Password":"pwd",
69+
"Claims": [
70+
{ "Type": "name", "Value": "User 02", "ValueType": "string" },
71+
{ "Type": "email", "Value": "user02@example.localhost", "ValueType": "string" }
72+
],
73+
}
74+
]
75+
volumes:
76+
db_data_sqlite:
77+
custom:

package-lock.json

Lines changed: 124 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"better-sqlite3": "11.8.1",
2929
"bull": "4.16.5",
3030
"cookie-parser": "1.4.7",
31+
"cookie-session": "^2.1.0",
3132
"cors": "2.8.5",
3233
"date-fns": "2.30.0",
3334
"dotenv": "16.4.7",
@@ -46,6 +47,7 @@
4647
"mysql2": "3.12.0",
4748
"nanoid": "3.3.8",
4849
"nodemailer": "6.9.16",
50+
"openid-client": "^5.7.0",
4951
"passport": "0.7.0",
5052
"passport-jwt": "4.0.1",
5153
"passport-local": "1.0.0",

server/env.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const spec = {
5050
REDIS_DB: num({ default: 0 }),
5151
DISALLOW_ANONYMOUS_LINKS: bool({ default: true }),
5252
DISALLOW_REGISTRATION: bool({ default: true }),
53+
DISALLOW_FORM_LOGIN: bool({ default: false }),
5354
SERVER_IP_ADDRESS: str({ default: "" }),
5455
SERVER_CNAME_ADDRESS: str({ default: "" }),
5556
CUSTOM_DOMAIN_USE_HTTPS: bool({ default: false }),
@@ -61,6 +62,13 @@ const spec = {
6162
MAIL_USER: str({ default: "" }),
6263
MAIL_FROM: str({ default: "", example: "Kutt <support@kutt.it>" }),
6364
MAIL_PASSWORD: str({ default: "" }),
65+
OIDC_ENABLED: bool({ default: false }),
66+
OIDC_ISSUER: str({ default: "" }),
67+
OIDC_CLIENT_ID: str({ default: "" }),
68+
OIDC_CLIENT_SECRET: str({ default: "" }),
69+
OIDC_SCOPE: str({ default: "openid profile email" }),
70+
OIDC_EMAIL_CLAIM: str({ default: "email" }),
71+
OIDC_APP_URL: str({ default: "" }),
6472
ENABLE_RATE_LIMIT: bool({ default: false }),
6573
REPORT_EMAIL: str({ default: "" }),
6674
CONTACT_EMAIL: str({ default: "" }),

server/handlers/auth.handler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ const CustomError = utils.CustomError;
1616
function authenticate(type, error, isStrict, redirect) {
1717
return function auth(req, res, next) {
1818
if (req.user) return next();
19-
19+
2020
passport.authenticate(type, (err, user, info) => {
2121
if (err) return next(err);
22+
if (type === 'oidc' && info instanceof Error) return next(info);
2223

2324
if (
2425
req.isHTML &&
@@ -80,6 +81,7 @@ const jwtPage = authenticate("jwt", "Unauthorized.", true, "page");
8081
const jwtLoose = authenticate("jwt", "Unauthorized.", false, "header");
8182
const jwtLoosePage = authenticate("jwt", "Unauthorized.", false, "page");
8283
const apikey = authenticate("localapikey", "API key is not correct.", false, null);
84+
const oidc = authenticate("oidc", "Unauthorized", false, "page");
8385

8486
function admin(req, res, next) {
8587
if (req.user.admin) return next();
@@ -388,6 +390,7 @@ module.exports = {
388390
local,
389391
login,
390392
newPassword,
393+
oidc,
391394
resetPassword,
392395
signup,
393396
verify,

server/handlers/locals.handler.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function config(req, res, next) {
2727
res.locals.server_ip_address = env.SERVER_IP_ADDRESS;
2828
res.locals.server_cname_address = env.SERVER_CNAME_ADDRESS;
2929
res.locals.disallow_registration = env.DISALLOW_REGISTRATION;
30+
res.locals.disallow_form_login = env.DISALLOW_FORM_LOGIN;
31+
res.locals.oidc_enabled = env.OIDC_ENABLED;
3032
res.locals.mail_enabled = env.MAIL_ENABLED;
3133
res.locals.report_email = env.REPORT_EMAIL;
3234
res.locals.custom_styles = utils.getCustomCSSFileNames();

0 commit comments

Comments
 (0)