Просмотр исходного кода

re-enable token fields from before

CauseFX 4 лет назад
Родитель
Сommit
8232d85115
3 измененных файлов с 33 добавлено и 32 удалено
  1. 26 25
      api/classes/organizr.class.php
  2. 4 4
      api/functions/sso-functions.php
  3. 3 3
      api/functions/token-functions.php

+ 26 - 25
api/classes/organizr.class.php

@@ -1205,20 +1205,20 @@ class Organizr
 					$this->setResponse(200, 'Token is valid');
 				}
 				return array(
-					"token" => $token,
-					"tokenDate" => $userInfo['tokenDate'],
-					"tokenExpire" => $userInfo['tokenExpire'],
-					"username" => $user['username'],
-					"uid" => $this->guestHash(0, 5),
-					"group" => $user['group'],
-					"groupID" => $user['group_id'],
-					"email" => $user['email'],
-					"image" => $user['image'],
-					"userID" => $user['id'],
-					"loggedin" => true,
-					"locked" => $user['locked'],
-					"tokenList" => $allTokens,
-					"authService" => explode('::', $user['auth_service'])[0]
+					'token' => $token,
+					'tokenDate' => $userInfo['tokenDate'],
+					'tokenExpire' => $userInfo['tokenExpire'],
+					'username' => $user['username'] ?? $userInfo['username'],
+					'uid' => $this->guestHash(0, 5),
+					'group' => $user['group'] ?? $userInfo['group'],
+					'groupID' => $user['group_id'] ?? $userInfo['groupID'],
+					'email' => $user['email'] ?? $userInfo['email'],
+					'image' => $user['image'] ?? $userInfo['image'],
+					'userID' => $user['id'] ?? $userInfo['userID'],
+					'loggedin' => true,
+					'locked' => $user['locked'] ?? 0,
+					'tokenList' => $allTokens,
+					'authService' => explode('::', $user['auth_service'])[0]
 				);
 			}
 		} else {
@@ -1246,15 +1246,15 @@ class Organizr
 				'token' => $token,
 				'tokenDate' => $userInfo['tokenDate'],
 				'tokenExpire' => $userInfo['tokenExpire'],
-				'username' => $user['username'],
+				'username' => $user['username'] ?? $userInfo['username'],
 				'uid' => $this->guestHash(0, 5),
-				'group' => $user['group'],
-				'groupID' => $user['group_id'],
-				'email' => $user['email'],
-				'image' => $user['image'],
-				'userID' => $user['id'],
+				'group' => $user['group'] ?? $userInfo['group'],
+				'groupID' => $user['group_id'] ?? $userInfo['groupID'],
+				'email' => $user['email'] ?? $userInfo['email'],
+				'image' => $user['image'] ?? $userInfo['image'],
+				'userID' => $user['id'] ?? $userInfo['userID'],
 				'loggedin' => true,
-				'locked' => $user['locked'],
+				'locked' => $user['locked'] ?? 0,
 				'tokenList' => $allTokens,
 				'authService' => explode('::', $user['auth_service'])[0]
 			);
@@ -3490,9 +3490,9 @@ class Organizr
 		->expiresAt(time() + (86400 * $days))// Configures the expiration time of the token (exp claim)
 		->withClaim('username', $result['username'])// Configures a new claim, called "username"
 		->withClaim('group', $result['group'])// Configures a new claim, called "group"
-		//->withClaim('groupID', $result['group_id'])// Configures a new claim, called "groupID"
-		//->withClaim('email', $result['email'])// Configures a new claim, called "email"
-		//->withClaim('image', $result['image'])// Configures a new claim, called "image"
+		->withClaim('groupID', $result['group_id'])// Configures a new claim, called "groupID"
+		->withClaim('email', $result['email'])// Configures a new claim, called "email"
+		->withClaim('image', $result['image'])// Configures a new claim, called "image"
 		->withClaim('userID', $result['id'])// Configures a new claim, called "image"
 		->sign($signer, $this->config['organizrHash'])// creates a signature using "testing" as key
 		->getToken(); // Retrieves the generated token
@@ -7075,7 +7075,8 @@ class Organizr
 			}
 			
 		} catch (Exception $e) {
-			return $e;
+			$this->debug($e->getMessage());
+			return false;
 		}
 		return count($request) > 1 ? $results : $results[$firstKey];
 	}

+ 4 - 4
api/functions/sso-functions.php

@@ -5,9 +5,9 @@ trait SSOFunctions
 	public function ssoCookies()
 	{
 		$cookies = array(
-			'myPlexAccessToken' => isset($_COOKIE['mpt']) ? $_COOKIE['mpt'] : false,
-			'id_token' => isset($_COOKIE['Auth']) ? $_COOKIE['Auth'] : false,
-			'jellyfin_credentials' => isset($_COOKIE['jellyfin_credentials']) ? $_COOKIE['jellyfin_credentials'] : false,
+			'myPlexAccessToken' => $_COOKIE['mpt'] ?? false,
+			'id_token' => $_COOKIE['Auth'] ?? false,
+			'jellyfin_credentials' => $_COOKIE['jellyfin_credentials'] ?? false,
 		);
 		// Jellyfin cookie
 		foreach (array_keys($_COOKIE) as $k => $v) {
@@ -164,7 +164,7 @@ trait SSOFunctions
 					$headers = array(
 						"Accept" => "application/json",
 						"Content-Type" => "application/x-www-form-urlencoded",
-						"User-Agent" => isset($_SERVER ['HTTP_USER_AGENT']) ? $_SERVER ['HTTP_USER_AGENT'] : null,
+						"User-Agent" => $_SERVER ['HTTP_USER_AGENT'] ?? null,
 						"X-Forwarded-For" => $this->userIP()
 					);
 					$data = array(

+ 3 - 3
api/functions/token-functions.php

@@ -27,10 +27,10 @@ trait TokenFunctions
 					$result['valid'] = true;
 					$result['username'] = ($jwttoken->hasClaim('username')) ? $jwttoken->getClaim('username') : 'N/A';
 					$result['group'] = ($jwttoken->hasClaim('group')) ? $jwttoken->getClaim('group') : 'N/A';
-					//$result['groupID'] = $jwttoken->getClaim('groupID');
+					$result['groupID'] = $jwttoken->getClaim('groupID');
 					$result['userID'] = $jwttoken->getClaim('userID');
-					//$result['email'] = $jwttoken->getClaim('email');
-					//$result['image'] = $jwttoken->getClaim('image');
+					$result['email'] = $jwttoken->getClaim('email');
+					$result['image'] = $jwttoken->getClaim('image');
 					$result['tokenExpire'] = $jwttoken->getClaim('exp');
 					$result['tokenDate'] = $jwttoken->getClaim('iat');
 					//$result['token'] = $jwttoken->getClaim('exp');