Browse Source

added master password support to Komga (#1838)

CauseFX 3 years ago
parent
commit
d6a9081d26
3 changed files with 15 additions and 0 deletions
  1. 1 0
      api/classes/organizr.class.php
  2. 1 0
      api/config/default.php
  3. 13 0
      api/functions/sso-functions.php

+ 1 - 0
api/classes/organizr.class.php

@@ -2600,6 +2600,7 @@ class Organizr
 				$this->settingsOption('blank'),
 				$this->settingsOption('username', 'komgaFallbackUser', ['label' => 'Komga Fallback Email', 'help' => 'DO NOT SET THIS TO YOUR ADMIN ACCOUNT. We recommend you create a local account as a "catch all" for when Organizr is unable to perform SSO.  Organizr will request a User Token based off of this user credentials']),
 				$this->settingsOption('password', 'komgaFallbackPassword', ['label' => 'Komga Fallback Password']),
+				$this->settingsOption('password', 'komgaSSOMasterPassword', ['label' => 'Komga Master Password', 'help' => 'Sets master password if using oAuth backend - This will set the password on the login form for logins using oAuth where no password is supplied.']),
 			],
 		];
 	}

+ 1 - 0
api/config/default.php

@@ -87,6 +87,7 @@ return [
 	'komgaURL' => '',
 	'komgaFallbackUser' => '',
 	'komgaFallbackPassword' => '',
+	'komgaSSOMasterPassword' => '',
 	'sonarrURL' => '',
 	'sonarrUnmonitored' => false,
 	'sonarrIcon' => true,

+ 13 - 0
api/functions/sso-functions.php

@@ -118,7 +118,20 @@ trait SSOFunctions
 	public function getKomgaToken($email, $password, $fallback = false)
 	{
 		$token = null;
+		$useMaster = false;
 		try {
+			if ($password) {
+				if ($password == '') {
+					$useMaster = true;
+				}
+			} else {
+				$useMaster = true;
+			}
+			if ($useMaster) {
+				if ($this->config['komgaSSOMasterPassword'] !== '') {
+					$password = $this->decrypt($this->config['komgaSSOMasterPassword']);
+				}
+			}
 			$credentials = array('auth' => new Requests_Auth_Digest(array($email, $password)));
 			$url = $this->qualifyURL($this->config['komgaURL']);
 			$options = $this->requestOptions($url, 60000, true, false, $credentials);