3 Replies Latest reply on Dec 2, 2013 6:24 PM by Steve Harman

    How to provide custom login responses in a .NET Backend Application

    Steve Harman



      I have a Backend built in .NET using a 'RhoConnect.NET like' implementation.


      It processes the HttpWebRequests from RhoConnect to authenticate logins with a request/response like the below:


      POST /rhoconnect/authenticate HTTP/1.1

                            Accept: application/json

                            Accept-Encoding: gzip, deflate

                            Content-Type: application/json

                            Content-Length: 63

                            User-Agent: Ruby

                            Host: x.x.x.x:3000




      HTTP/1.1 200 OK

                            Content-Type: text/plain

                            X-Ua-Compatible: IE=Edge

                            Etag: "9990775155c3518a0d7917f7780b24aa"

                            Cache-Control: max-age=0, private, must-revalidate

                            X-Request-Id: 18fbb064e6597f397800c06d2c14ca8f

                            X-Runtime: 0.005002

                            Content-Length: 3

                            Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-02-16)

                            Date: Fri, 03 May 2013 01:21:15 GMT

                            Connection: Keep-Alive




      How can I respond to the POST RhoConnect/authenticate with an appropriate HttpWebResponse that gives me something equivalent to the Rho::Exception::LoginException that I can use back at the client?


      At the moment I only know how to respond with a HttpWebResponse StatusCode 200 OK for 'passed', or statucCode !=200 for failed including optional Username in the HttpWebResonse body for an alternate partition name. This doesn't give me the ability to tell mobile users why the authenticate request failed.


      Can this be done?




        • Re: How to provide custom login responses in a .NET Backend Application

          Currently rhoconnect does not support custom http response messages in the authenticate route.  This is the case whether or not you're using plugins like the .NET one.  When you say `Rho::Exception::LoginException` are you referring to the source adapter exception api?  If so that exception is only designed to be used from inside the source adapter model code, as it's a ruby api.




          There are two workarounds:


          1) Encode an error message in the username along with a non-200 response code

          2) Return the error in one of the models (i.e. the one you designate with the first sync priority)


          USER03520 please correct me if I'm wrong here or I'm missing something.

            • Re: How to provide custom login responses in a .NET Backend Application

              First option (encoding error message into the returned user-name) won't work. We only use that when code is 200. It should never be used in case of error.

              Second option (returning the error in a first synced model) also won't work because syncing is possible only after the authentication had succeeded, i.e. user is created. Here, situation is different.


              Currently, where would be no way to return custom error message to the client from the plugin. DynamicAdapter (which handles  the plugins)  does not store this info.

              The only thing that can potentially work - is to implement in .NET some route that says "Last_Error" and call it directly from the client.


              This should be considered as a future enhancement. We can parse the response from the plugin and post it back to the client instead of default LoginException response.