Skip to content

Commit

Permalink
Fix initialize openid auth strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Nov 19, 2023
1 parent e07d17c commit 89eb857
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
5 changes: 5 additions & 0 deletions server/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class Auth {
* Passport use OpenIDClient.Strategy
*/
initAuthStrategyOpenID() {
if (!Database.serverSettings.isOpenIDAuthSettingsValid) {
Logger.error(`[Auth] Cannot init openid auth strategy - invalid settings`)
return
}

const openIdIssuerClient = new OpenIDClient.Issuer({
issuer: global.ServerSettings.authOpenIDIssuerURL,
authorization_endpoint: global.ServerSettings.authOpenIDAuthorizationURL,
Expand Down
10 changes: 5 additions & 5 deletions server/controllers/MiscController.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,18 @@ class MiscController {
switch (type) {
case 'add':
this.watcher.onFileAdded(libraryId, path)
break;
break
case 'unlink':
this.watcher.onFileRemoved(libraryId, path)
break;
break
case 'rename':
const oldPath = req.body.oldPath
if (!oldPath) {
Logger.error(`[MiscController] Invalid request body for updateWatchedPath. oldPath is required for rename.`)
return res.sendStatus(400)
}
this.watcher.onFileRename(libraryId, oldPath, path)
break;
break
default:
Logger.error(`[MiscController] Invalid type for updateWatchedPath. type: "${type}"`)
return res.sendStatus(400)
Expand Down Expand Up @@ -670,6 +670,8 @@ class MiscController {
}

if (hasUpdates) {
await Database.updateServerSettings()

// Use/unuse auth methods
Database.serverSettings.supportedAuthMethods.forEach((authMethod) => {
if (originalAuthMethods.includes(authMethod) && !Database.serverSettings.authActiveAuthMethods.includes(authMethod)) {
Expand All @@ -682,8 +684,6 @@ class MiscController {
this.auth.useAuthStrategy(authMethod)
}
})

await Database.updateServerSettings()
}

res.json({
Expand Down
23 changes: 14 additions & 9 deletions server/objects/settings/ServerSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,7 @@ class ServerSettings {

// remove uninitialized methods
// OpenID
if (this.authActiveAuthMethods.includes('openid') && (
!this.authOpenIDIssuerURL ||
!this.authOpenIDAuthorizationURL ||
!this.authOpenIDTokenURL ||
!this.authOpenIDUserInfoURL ||
!this.authOpenIDJwksURL ||
!this.authOpenIDClientID ||
!this.authOpenIDClientSecret
)) {
if (this.authActiveAuthMethods.includes('openid') && !this.isOpenIDAuthSettingsValid) {
this.authActiveAuthMethods.splice(this.authActiveAuthMethods.indexOf('openid', 0), 1)
}

Expand Down Expand Up @@ -235,6 +227,19 @@ class ServerSettings {
return ['local', 'openid']
}

/**
* Auth settings required for openid to be valid
*/
get isOpenIDAuthSettingsValid() {
return this.authOpenIDIssuerURL &&
this.authOpenIDAuthorizationURL &&
this.authOpenIDTokenURL &&
this.authOpenIDUserInfoURL &&
this.authOpenIDJwksURL &&
this.authOpenIDClientID &&
this.authOpenIDClientSecret
}

get authenticationSettings() {
return {
authActiveAuthMethods: this.authActiveAuthMethods,
Expand Down

0 comments on commit 89eb857

Please sign in to comment.