Skip to content

Commit

Permalink
🐛 Fix existing sessions when using the latest version with Openid (ac…
Browse files Browse the repository at this point in the history
  • Loading branch information
lelemm authored and meonkeys committed Dec 2, 2024
1 parent 8766c24 commit 53b429f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
27 changes: 19 additions & 8 deletions migrations/1719409568000-multiuser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import getAccountDb from '../src/account-db.js';
import * as uuid from 'uuid';

export const up = async function () {
await getAccountDb().exec(
`
BEGIN TRANSACTION;
const accountDb = getAccountDb();

accountDb.transaction(() => {
accountDb.exec(
`
CREATE TABLE users
(id TEXT PRIMARY KEY,
user_name TEXT,
Expand All @@ -24,8 +26,6 @@ export const up = async function () {
ALTER TABLE files
ADD COLUMN owner TEXT;
DELETE FROM sessions;
ALTER TABLE sessions
ADD COLUMN expires_at INTEGER;
Expand All @@ -34,9 +34,20 @@ export const up = async function () {
ALTER TABLE sessions
ADD COLUMN auth_method TEXT;
COMMIT;
`,
);
);

const userId = uuid.v4();
accountDb.mutate(
'INSERT INTO users (id, user_name, display_name, enabled, owner, role) VALUES (?, ?, ?, 1, 1, ?)',
[userId, '', '', 'ADMIN'],
);

accountDb.mutate(
'UPDATE sessions SET user_id = ?, expires_at = ?, auth_method = ? WHERE auth_method IS NULL',
[userId, -1, 'password'],
);
});
};

export const down = async function () {
Expand Down
4 changes: 3 additions & 1 deletion src/account-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export function getLoginMethod(req) {
return req.body.loginMethod;
}

return config.loginMethod || 'password';
const activeMethod = getActiveLoginMethod();

return config.loginMethod || activeMethod || 'password';
}

export async function bootstrap(loginSettings) {
Expand Down
3 changes: 1 addition & 2 deletions src/accounts/openid.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ export function isValidRedirectUrl(url) {
const redirectUrl = new URL(url);
const serverUrl = new URL(serverHostname);

// Compare origin (protocol + hostname + port)
if (redirectUrl.origin === serverUrl.origin) {
if (redirectUrl.hostname === serverUrl.hostname) {
return true;
} else {
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/app-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ app.get('/needs-bootstrap', (req, res) => {
status: 'ok',
data: {
bootstrapped: !needsBootstrap(),
loginMethods: listLoginMethods(),
loginMethod: getLoginMethod(),
availableLoginMethods: listLoginMethods(),
multiuser: getActiveLoginMethod() === 'openid',
},
});
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/507.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [lelemm]
---

Fixed bug where the openid migration was removing access for users

0 comments on commit 53b429f

Please sign in to comment.