Jump to content


Photo

[API] Login with external form

api login form php

  • Please log in to reply
2 replies to this topic

#1 LanternMyWilly OFFLINE  

LanternMyWilly

    Newbie

  • Members
  • 2 posts
  • Local time: 07:38 PM

Posted 03 February 2020 - 12:06 PM

Hi!

 

I'm trying to create a webform where you can create an account and login into Emby without having to login in 'https://domain.com/w...html?serverId=123'. 

I've noticed that when you authenticate a user, this user stays authenticated throughout the entire browser. So I thought if I did a '/Users/AuthenticateByName' call in the form, this would would authenticate the user like it would when you normally login but it doesn't.

 

So basically I call '/Users/AuthenticateByName' with my desired username and password I want to login, this does the job but when I go to the same url as provided in the api call, it still asks me to login. Both in the same browser.

 

My code to authenticate the user: 

function userAuthenticate($username,$password)
    {
        $dataArray = array("Username"=>$username, "Pw"=>$password);
        $dataString = http_build_query($dataArray);
        $url= 'https://domain.com/emby/Users/AuthenticateByName?api_key=123456789&';

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($ch);
        curl_close($ch);
        $responseDecoded = json_decode($response,true);
        echo $responseDecoded["AccessToken"];
    }

The code above does always succeed but doesn't do what I want (that is authenticating the user in https://domain.com/web).

 

Now I'm wondering if it is possible to accomplish what I just described.

 

Thanks in advance!

(I'm sorry if I didn't describe my problem very well, I didn't really know how to  :unsure: )

 

Greetings!



#2 Luke OFFLINE  

Luke

    System Architect

  • Administrators
  • 153340 posts
  • Local time: 01:38 PM

Posted 03 February 2020 - 01:17 PM

Hi, I"m not sure. we dont' have any examples of this right now.



#3 LanternMyWilly OFFLINE  

LanternMyWilly

    Newbie

  • Members
  • 2 posts
  • Local time: 07:38 PM

Posted 07 February 2020 - 08:37 PM

Hi

 

I found some kind of solution that I'd like to share, I'm just wondering if it's frowned upon to add/adjust code to fit your needs? If so, I'll just drop it, if not I'm happy to share my findings.

The 'overwritten at every update' issue is no longer valid since I created a script that will make the changes every update (unless of course some major things change).







Also tagged with one or more of these keywords: api, login, form, php

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users