Ver Fonte

Emby invite working!

Noah Witt há 7 anos atrás
pai
commit
b11c446192

+ 1 - 1
api/functions/api-functions.php

@@ -1182,4 +1182,4 @@ function getSchema()
 	} else {
 		return 'DB not set yet...';
 	}
-}
+}

+ 38 - 6
api/functions/organizr-functions.php

@@ -2122,23 +2122,56 @@ function embyJoin($username, $email, $password)
 		$data = array ();
 		$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/New?name=' . $username . '&api_key=' . $GLOBALS['INVITES-embyApiKey'];
 		$response = Requests::Post($url, $headers, json_encode($data), array());
-		$response = json_decode($response);
+		$response = $response->body;
+		//return($response);
+		$response = json_decode($response, true);
+		//return($response);
 		$userID = $response["Id"];
+		//return($userID);
+
+		#authenticate as user to update password.
+
+		//randomizer four digits of DeviceId
+		// I dont think ther would be security problems with hardcoding deviceID but randomizing it would mitigate any issue.
+		$deviceIdSeceret = rand(0, 9)."".rand(0, 9)."".rand(0,9)."".rand(0,9);
+
+		//hardcoded device id with the first three digits random 0-9,0-9,0-9,0-9
+		$embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", DeviceId="'.$deviceIdSeceret.'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"';
+		$headers = array(
+			"Accept" => "application/json",
+			"Content-Type" => "application/json",
+			"X-Emby-Authorization" => $embyAuthHeader
+		);
+		$data = array (
+			"Pw" => "",
+			"Username" => $username
+		);
+		$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/AuthenticateByName';
+		$response = Requests::Post($url, $headers, json_encode($data), array());
+		$response = $response->body;
+		$response = json_decode($response, true);
+		$userToken = $response["AccessToken"];
 
 		#update password
+		$embyAuthHeader = 'MediaBrowser Client="Emby Mobile", Device="Firefox", Token="'.$userToken.'", DeviceId="'.$deviceIdSeceret.'aWxssS81LgAggFdpbmRvd3MgTlQgMTAuMDsgV2luNjxx7IHf2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMTkgU2FmYXJpLzUzNy4zNnwxNTUxNTczMTAyNDI4", Version="4.0.2.0"';
+
 		$headers = array(
-			"Accept" => "application/json"
+			"Accept" => "application/json",
+			"Content-Type" => "application/json",
+			"X-Emby-Authorization" => $embyAuthHeader
 		);
 		$data = array (
 			"CurrentPw" => "",
-			"Pw" => $password
+			"NewPw" => $password,
+			"Id" => $userID
 		);
-		$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Password?api_key=' . $GLOBALS['INVITES-embyApiKey'];
+		$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Password';
 		Requests::Post($url, $headers, json_encode($data), array());
 
 		#update config
 		$headers = array(
-			"Accept" => "application/json"
+			"Accept" => "application/json",
+			"Content-Type" => "application/json"
 		);
 		$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Policy?api_key=' . $GLOBALS['INVITES-embyApiKey'];
 		$response = Requests::Post($url, $headers, $GLOBALS['INVITES-EmbyDefaultUserConfig'], array());
@@ -2153,7 +2186,6 @@ function embyJoin($username, $email, $password)
 		#);
 		#$url = $GLOBALS['INVITES-EmbyAddress'] . '/emby/Users/' . $userID . '/Connect/Link?api_key=' . $GLOBALS['INVITES-embyApiKey'];
 		#Request::Post($url, $headers, json_encode($data), array());
-
 	} catch (Requests_Exception $e) {
 		writeLog('error', 'Emby Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
 	};

+ 2 - 2
api/plugins/js/invites.js

@@ -437,12 +437,12 @@ $(document).on('click', '.inviteModal', function() {
                                 <input type="text" class="form-control" id="inviteUsernameInvite" placeholder="Emby Username" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus="" required="">
                             </div>
                             <br />
-                            <button class="btn btn-block btn-info" onclick="hasEmbyUsername();">Submit</button>
+                            <button class="btn btn-block btn-info" onclick="hasPlexUsername();">Submit</button>
                         </div>
                         <div class="form-group invite-step-3-emby-no hidden">
                             <div class="input-group" style="width: 100%;">
                                 <div class="input-group-addon hidden-xs"><i class="ti-user"></i></div>
-                                <input type="text" class="form-control" id="invitePlexEmbyUsername" lang="en" placeholder="Username" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus="" required="">
+                                <input type="text" class="form-control" id="inviteEmbyJoinUsername" lang="en" placeholder="Username" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" autofocus="" required="">
                             </div>
                             <div class="input-group" style="width: 100%;">
                                 <div class="input-group-addon hidden-xs"><i class="ti-email"></i></div>