Announcement

Collapse
No announcement yet.

Call in to plug-in from external web pages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call in to plug-in from external web pages

    I have a need to be able to take a posting from an external webserver and process the data in my plug-in.

    I think I could handle this with an aspx page and then populate a device in HS, but it seems a clunky way to do this.

    I would rather register a web page within my plug-in and use this as the callback page, but I can't seem to figure out how to obtain the data being posted.

    The external URL being called would be something like:

    http://myhssite.here.com/iz_Callback#token=ACCESS_TOKEN

    What I need is to be able to pick up the #token=ACCESS_TOKEN bit, but I never seem to get the callback to the page I have registered (because there are no formdata I guess??)

    Anyone got any suggestions on how I can achieve my desired outcome please?
    Nicolai L

  • #2
    If you stick this

    Code:
      Dim parts As Collections.Specialized.NameValueCollection = Nothing
                If (queryString <> "") Then
                    parts = HttpUtility.ParseQueryString(queryString)
    
                    For Each key As String In parts.AllKeys
                        Log("(TEMP) Key:" & key & " Value:" & parts(key), LogType.LOG_TYPE_WARNING)
                    Next
    
                End If
    in your GetPagePlugIn and call it like:

    http://hsserver/RegisteredPageName?Token=123456


    Does that work?

    Paul..

    Comment


    • #3
      I'm not sure the # is going to be helpful because I've just checked and calling a registered webpage with a # fragment in the URL does not pass it to GetPagePlugin. You are only going to be getting the query string as I guess HS is taking out the # as it does not think you need it.
      My Plugins:

      Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
      Yeelight 3P | Nanoleaf 3P

      Comment


      • #4
        Originally posted by mrhappy View Post
        I'm not sure the # is going to be helpful because I've just checked and calling a registered webpage with a # fragment in the URL does not pass it to GetPagePlugin. You are only going to be getting the query string as I guess HS is taking out the # as it does not think you need it.
        That was my experience as well. Unfortunately I don't have control over the syntax from the calling website. It's part of the login to the Neato site and the callback is the website passing the autentication token that I need to use in subsequent calls.

        Got to find a way to do this?
        Nicolai L

        Comment


        • #5
          Originally posted by NicolaiL View Post
          That was my experience as well. Unfortunately I don't have control over the syntax from the calling website. It's part of the login to the Neato site and the callback is the website passing the autentication token that I need to use in subsequent calls.

          Got to find a way to do this?
          Do you have control over the url that is called back from the remote server?
          Does the communication need to have SSL?

          Paul..

          Comment


          • #6
            Originally posted by sooty View Post
            Do you have control over the url that is called back from the remote server?
            Does the communication need to have SSL?

            Paul..
            This is for an OAuth call to Neato's API. I have no control over the URL and yes, it has to be SSL.

            All a bit of a pain! but somehow must be doable.

            I did look for OAuth .net packages to use, but didn't find anything that looked particularly suitable so I thought I'd try and build it natively.
            Nicolai L

            Comment


            • #7
              I was totally missing the point until you mentioned Oauth2

              Assuming you are going down the implicit route then I expect you're gonna need an html page and some javascript to get the token from the hash fragment.

              Paul..

              Comment


              • #8
                Originally posted by NicolaiL View Post
                This is for an OAuth call to Neato's API. I have no control over the URL and yes, it has to be SSL.

                All a bit of a pain! but somehow must be doable.

                I did look for OAuth .net packages to use, but didn't find anything that looked particularly suitable so I thought I'd try and build it natively.
                Host a web page on some hosting with a re-direct that has the data from OAuth and then posts it to your HS page in the plugin? I've looked at OAuth and HS plugins before and wondered how to do it as I wonder about people that don't allow external access to their HS system.
                My Plugins:

                Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
                Yeelight 3P | Nanoleaf 3P

                Comment


                • #9
                  Originally posted by sooty View Post
                  I was totally missing the point until you mentioned Oauth2

                  Assuming you are going down the implicit route then I expect you're gonna need an html page and some javascript to get the token from the hash fragment.

                  Paul..
                  Yeah, I get I need an html page, but I guess it's the JS but I'm struggling with.

                  Do you have any examples? Have you done anything similar?
                  Nicolai L

                  Comment


                  • #10
                    Originally posted by mrhappy View Post
                    Host a web page on some hosting with a re-direct that has the data from OAuth and then posts it to your HS page in the plugin? I've looked at OAuth and HS plugins before and wondered how to do it as I wonder about people that don't allow external access to their HS system.
                    Nice workaround, but I ultimately want this to be a plug-in that is available to others as well, so for me to host a page might not be the best route.

                    Agreed, there are some folks who don't want access to their local systems, but that will probably be a limitation as the OAuth demands a callback URI
                    Nicolai L

                    Comment


                    • #11
                      I've not done anything with Oauth2 but the code below should give you an idea how to get what you want from the hash fragment.

                      PHP Code:
                      <html>
                       <
                      head>
                          <
                      script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
                          <
                      script>
                          $( 
                      document ).ready(function() {
                          var 
                      oauthParams location.hash.substring(1);
                          var 
                      output document.getElementById('oauthParams');
                          
                      output.innerHTML oauthParams;
                                  });
                          
                          </
                      script>
                       </
                      head>
                      <
                      body>
                          <
                      div id="oauthParams"/div>
                      </
                      body>
                      </
                      html
                      Save it as an html file and call it like:

                      /yourfilename.html#TOKEN=123456&SOMEOTHERDATA=ABCDEF

                      assuming there's something after the # you should see it should output it.

                      Paul..

                      Comment


                      • #12
                        Thanks, Paul. I will give that a try. I guess I then need to figure out how I feed that data back into the plug-in?

                        (I'm not good on JS as you can probably tell ...)
                        Nicolai L

                        Comment


                        • #13
                          Reading the data using inline elements in not that easy especially if you want to have this working on both Windows and Linux.

                          In Windows VB.NET, it is normally necessary to use the Windows.Forms Webbrowser control to read specific inline elements from a web page. As this uses IE, it is not supported on Linux. Mono does have its equivalent so you may need to write two versions.

                          Alternatively, you would have to pass back the JavaScript variable using AJAX in an ASPX page. The problem is that ASPX is not supported on Pi's.
                          Jon

                          Comment


                          • #14
                            Thanks for the tip, Jon. Looks like I got a bit more thinking/trying/testing ahead of me...
                            Nicolai L

                            Comment

                            Working...
                            X