Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Senior Member
    Join Date
    May 2008
    Location
    Canada
    Posts
    2,824

    async::HTTP::Server usage

    Hi - I'm trying to extend YT plugin to add personal account. In the need to handle OAuth2, there has to be a webserver to handle the redirect_uri and get the access_token once the user has given his authorization using a web browser. Can I use, in LMS, the Async::HTTP::Server to have a short lifetime webserver or do I need to do a lower level sync with socket & addRead?
    LMS 7.7, 7.8 and 7.9 - 5xRadio, 3xBoom, 4xDuet, 1xTouch, 1 SB2. Sonos PLAY:3, PLAY:5, Marantz NR1603, JBL OnBeat, XBoxOne, XBMC, Foobar2000, ShairPortW, JRiver 21, 2xChromecast Audio, Chromecast v1 and v2, , Pi B3, B2, Pi B+, 2xPi A+, Odroid-C1, Odroid-C2, Cubie2, Yamaha WX-010, AppleTV 4, Airport Express

  2. #2
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    19,475

    async::Server usage

    Wouldn't a regular page handler do (Slim::Web::Pages->addPageFunction())?

    --

    Michael

  3. #3
    Senior Member meep's Avatar
    Join Date
    Aug 2007
    Location
    Ireland
    Posts
    148
    I'm using HTTP:aemon....

    Code:
            $d = HTTP::Daemon -> new(ReuseAddr => 1, LocalPort => $prefport);
    
    
            if (defined $d) {   # check if HTTP::Demon initialised
             
                myDebug("Started HTTPD: ".$d);
                my $addy = $d -> url;
                myDebug("Proxy Server Listening: $addy", "info");
    
    
                # register daemon with LMS select loop
                # so it gets polled each cycle
    
                Slim::Utils::Network::blocking($d, 0);
                Slim::Networking::Select::addRead($d, \&handleIncomingConnect);
    
    
            } else {
    
    
                # no HTTPd
                myDebug("Proxy Server Not Started (HTTPd not initialising)", "info");
    
    
            }
    Might be overkill for what you need, and you need an open port on the users router which is proving significantly problematic for me.


    ALEXA LMS SKILL: http://www.hab-tunes.com | Twitter: #habtunes
    Personal HA BLOG: http://mediaserver8.blogspot.com

    Squeezebox | Squeezebox Radio x 2 | Squeezebox Duet

  4. #4
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    19,475

    async::HTTP::Server usage

    > I'm using HTTP:aemon....

    But you're using it because you want to run another web server on a
    different port, don't you? For most other use cases using the built-in
    server should be the first choice. It's there, it's working, it has
    templating support already etc. Why re-invent the wheel? Us what is
    there and concentrate on your application, rather than the infrastructure.

    --

    Michael

  5. #5
    Senior Member
    Join Date
    May 2008
    Location
    Canada
    Posts
    2,824
    What is needed it incredibly simple (as far as I understand, but this is the 1st time i'm trying oauth): the service platform (YT in that case) need an URL to make a GET once the user has agreed. That GET request will contain a token_access parameter. All I need is wait for that GET and extract the token_access. And it's only needed for a very short time, I don't need (and I don't think I should) let such server running
    Last edited by philippe_44; 2017-01-19 at 16:04.
    LMS 7.7, 7.8 and 7.9 - 5xRadio, 3xBoom, 4xDuet, 1xTouch, 1 SB2. Sonos PLAY:3, PLAY:5, Marantz NR1603, JBL OnBeat, XBoxOne, XBMC, Foobar2000, ShairPortW, JRiver 21, 2xChromecast Audio, Chromecast v1 and v2, , Pi B3, B2, Pi B+, 2xPi A+, Odroid-C1, Odroid-C2, Cubie2, Yamaha WX-010, AppleTV 4, Airport Express

  6. #6
    Senior Member meep's Avatar
    Join Date
    Aug 2007
    Location
    Ireland
    Posts
    148
    Quote Originally Posted by mherger View Post
    > I'm using HTTP:aemon....

    But you're using it because you want to run another web server on a
    different port, don't you? For most other use cases using the built-in
    server should be the first choice. It's there, it's working, it has
    templating support already etc. Why re-invent the wheel? Us what is
    there and concentrate on your application, rather than the infrastructure.

    --

    Michael
    indeed, and my life has become immeasurably easier since I started working with the platform rather than against it - biggest learning so far.


    ALEXA LMS SKILL: http://www.hab-tunes.com | Twitter: #habtunes
    Personal HA BLOG: http://mediaserver8.blogspot.com

    Squeezebox | Squeezebox Radio x 2 | Squeezebox Duet

  7. #7
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    19,475

    async::HTTP::Server usage

    > What is needed it incredibly simple (as far as I understand, but this is
    > the 1st time i'm trying oauth): the service platform (YT in that case)
    > need an URL to make a GET once the user as agreed. That GET request will
    > contain a token_access parameter. All I need is wait for that GET and
    > extract the token_access


    And IIRC this URL only needs to be reachable from the client from which
    you trigger the oauth flow - which would be inside your network. Your
    browser would be re-directed to that page. No need to be accessible from
    outside your home. addPageFunction should be all you need. You could
    even re-use the settings page handler for this.

    --

    Michael

  8. #8
    Senior Member
    Join Date
    May 2008
    Location
    Canada
    Posts
    2,824

    async::HTTP::Server usage

    Quote Originally Posted by mherger View Post
    Wouldn't a regular page handler do (Slim::Web::Pages->addPageFunction())?

    --

    Michael
    indeed it does - I've just not really added extra pages in LMS so far, so now I know :-) Will play with oauth over the weekend

    Thank you, as always

    [edit] .... argh, could not resist to try, and hit a rock: the oauth works, I got the callback but the uri that is returned by the YT server is something like
    Code:
    http://localhost/oauth2callback#access_token=1/QbIbRMWW&token_type=Bearer&expires_in=3600
    So I have the path
    Code:
    http://localhost/oauth2callback
    but all the other part of the uri (the one I really want) is stripped from any parameter of the callback, i.e. I miss
    Code:
    #access_token=1/QbIbRMWW&token_type=Bearer&expires_in=3600
    I dumped the whole @_ and it's not there. Any idea if there is a way to get the complete ressource?
    Last edited by philippe_44; 2017-01-20 at 00:20.
    LMS 7.7, 7.8 and 7.9 - 5xRadio, 3xBoom, 4xDuet, 1xTouch, 1 SB2. Sonos PLAY:3, PLAY:5, Marantz NR1603, JBL OnBeat, XBoxOne, XBMC, Foobar2000, ShairPortW, JRiver 21, 2xChromecast Audio, Chromecast v1 and v2, , Pi B3, B2, Pi B+, 2xPi A+, Odroid-C1, Odroid-C2, Cubie2, Yamaha WX-010, AppleTV 4, Airport Express

  9. #9
    Senior Member
    Join Date
    May 2008
    Location
    Canada
    Posts
    2,824
    Quote Originally Posted by philippe_44 View Post
    indeed it does - I've just not really added extra pages in LMS so far, so now I know :-) Will play with oauth over the weekend

    Thank you, as always

    [edit] .... argh, could not resist to try, and hit a rock: the oauth works, I got the callback but the uri that is returned by the YT server is something like
    Code:
    http://localhost/oauth2callback#access_token=1/QbIbRMWW&token_type=Bearer&expires_in=3600
    So I have the path
    Code:
    http://localhost/oauth2callback
    but all the other part of the uri (the one I really want) is stripped from any parameter of the callback, i.e. I miss
    Code:
    #access_token=1/QbIbRMWW&token_type=Bearer&expires_in=3600
    I dumped the whole @_ and it's not there. Any idea if there is a way to get the complete ressource?
    Michael, I edited that message so you might not have seen the update/problem (no urgency, just wanted to make sure that you see it)
    LMS 7.7, 7.8 and 7.9 - 5xRadio, 3xBoom, 4xDuet, 1xTouch, 1 SB2. Sonos PLAY:3, PLAY:5, Marantz NR1603, JBL OnBeat, XBoxOne, XBMC, Foobar2000, ShairPortW, JRiver 21, 2xChromecast Audio, Chromecast v1 and v2, , Pi B3, B2, Pi B+, 2xPi A+, Odroid-C1, Odroid-C2, Cubie2, Yamaha WX-010, AppleTV 4, Airport Express

  10. #10
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    19,475

    async::HTTP::Server usage

    >> I dumped the whole @_ and it's not there. Any idea if there is a way
    >> to get the complete ressource?


    Wouldn't it be in $params->{url_query} and/or $params->{path}?

    I guess your URL would be localhost:9000, not port 80?

    --

    Michael

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •