Jump to content

Does EasyPassword work?


Go to solution Solved by Robert87354,

Recommended Posts

Robert87354
Posted (edited)

Hi,

I'm giving Emby another try, currently I'm using Jellyfin and creating new users with password included with no problem with PHP, but on amby it doesn't work, I'm trying EasyPassword with no success. Has anyone got it working?

Curl

curl -X POST "http://localhost:8096/Users/{$user_id}/Password?api_key=xxxxx" -H "accept: */*" -H "Content-Type: application/json" -d "{\"CurrentPw\":\"\",\"NewPw\":\"test\"}" 

 

PHP

$ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "$url_emby/Users/{$userid}/EasyPassword?api_key=$api_emby");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"NewPw\":\"{$password}\",\"ResetPassword\":false}");
  //curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"CurrentPw\":\"\",{\"NewPw\":\"{$password}\"}");

  $headers = array();
  $headers[] = 'Accept: */*';
  $headers[] = 'Content-Type: application/json';
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $result4 = curl_exec($ch);
  if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
  }
curl_close($ch);

$json4 = json_decode($result4, true);

 

The creation of a new user with password is working in Jellyfin, but in emby it is different, it does not work this way
 

$ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "$url_jellyfin/Users/New?api_key=$api_jellyfin");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"Name\":\"{$mailuser}\",\"Password\":\"{$password}\"}");

  $headers = array();
  $headers[] = 'Accept: application/json';
  $headers[] = 'Content-Type: application/json';
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $result = curl_exec($ch);

  if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
  }
curl_close($ch);

$json = json_decode($result, true);


$userid = $json['Id'];

 

Edited by Robert87354
Posted

All feature which are depending on a "local network" vs. "non-local network" distinction are getting phased out. This is was decided in consequence of a recent security incident which has shown that this distinction cannot be safely made while fulfilling all user demands for different network setups.

New ways for logging-in easily and comfortably will be added to the client apps.

I wouldn't recommend doing development relying on the "Easy Password" feature anymore.

What's the purpose of your script?

Robert87354
Posted

I need to create new users with their corresponding password, currently I use jellyfin and I have no problems, but in emby I am not able to make it work, the user creates it, but I cannot define a password for it :(

Posted

IIRC, you need to create the user first and set the password in a second step. Have you tried that?

Robert87354
Posted (edited)

The user creates it successfully with PHP, the problem is that EasyPassword and API Password does not work, tested in PHP and with curl.

Create user successfully

$ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "$url_emby/Users/New?api_key=$api_emby");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  //curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"Name\":\"{$mailuser}\",\"Password\":\"{$codigo_amigo}\"}");
  curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"Name\":\"{$mailuser}\"}");

  $headers = array();
  $headers[] = 'Accept: application/json';
  $headers[] = 'Content-Type: application/json';
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $result = curl_exec($ch);

  if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
  }
curl_close($ch);

$json = json_decode($result, true);


$userid = $json['Id'];

Does not work with EasyPassword or Password

$ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "$url_emby/Users/{$userid}/EasyPassword?api_key=$api_emby");
  //curl_setopt($ch, CURLOPT_URL, "$url_emby/Users/{$userid}/Password?api_key=$api_emby")
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"NewPw\":\"{$code}\",\"ResetPassword\":ture}");
  //curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"CurrentPw\":\"\",{\"NewPw\":\"{$codigo_amigo}\"}");

  $headers = array();
  $headers[] = 'Accept: */*';
  $headers[] = 'Content-Type: application/json';
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $result4 = curl_exec($ch);
  if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
  }
curl_close($ch);

$json4 = json_decode($result4, true);


It doesn't work with curl either.

 

curl -X POST "http://IP:8096/Users/{$user_id}/Password?api_key=xxxxx" -H "accept: */*" -H "Content-Type: application/json" -d "{\"CurrentPw\":\"\",\"NewPw\":\"test\"}" 

Jellyfin creates username and password without problems with PHP, but this doesn't work on emby

$ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "$url_jellyfin/Users/New?api_key=$api_jellyfin");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"Name\":\"{$mailuser}\",\"Password\":\"{$password}\"}");

  $headers = array();
  $headers[] = 'Accept: application/json';
  $headers[] = 'Content-Type: application/json';
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $result = curl_exec($ch);

  if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
  }
curl_close($ch);

$json = json_decode($result, true);


$userid = $json['Id'];


I've read many threads on this forum and none of them solve the problem, so I think it's an API problem.

Thank you very much for your help.

Edited by Robert87354
Posted

I've never done this specifically, so I can't tell exactly why it might go wrong, but what you can do is just watch how the web app is doing it.
Just connect to Emby Server with a browser and watch the network requests in dev tools while setting a password.
Then compare with what you are doing.

  • Solution
Robert87354
Posted

Resolved.

Fixed, to create the user it is not necessary to emby in the url, but to define a password, and only NewPw should be used.

 

$ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "$url_emby/emby/Users/{$userid}/Password?api_key=$api_emby");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"NewPw\":\"{$codigo_amigo}\"}");

  $headers = array();
  $headers[] = 'Accept: */*';
  $headers[] = 'Content-Type: application/json';
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

  $result4 = curl_exec($ch);
  if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
  }
curl_close($ch);

$json4 = json_decode($result4, true);


 


 

  • Like 1
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...