1 Reply Latest reply on Aug 29, 2016 11:01 PM by devgeeks@adobe

    My Phonegap app does not send back JSESSIONID.

    nigras

      I have a simple phonegap app that allows users to authenticate with username and password, the server sends back JSESSIONID. However when I call a web service that shows user's courses upon login, server responds with "401 authentication required" meaning the JSESSIONID was not sent back to the server and the server does not know the user is already authenticated.

      This is the phonegap code where the user authenticates (by using just username for test):

       

      $(document).ready(function(){

          $('#loginbutton').on('click', function(){

          var useremail= $("#email").val();

          //var password= $("#password").val();

             

          $.ajax({

                      url: baseurl+ "/rest/login",

                      method: 'POST',

                      contentType: 'application/x-www-form-urlencoded',

                      dataType: "json",

                      data: { id: useremail },

                      success: function (result) {

                      if(result.status=="OK"){

                      $.mobile.changePage('#courselistpage', {

                    transition: "slide"

                 });

                      } else {

                      alert('loginerror');

                      }

                      }, error: function (e) {

                          alert(JSON.stringify(e));

                      }

                  });

              // courselist=[{'id':1, "name": "course1"}, {'id':2, "name":'course2'}, {'id':3, 'name': 'course3'}];

              // $.mobile.changePage('#courselistpage', {

              //     transition: "slide"

              // });

          });

      });

       

      This is the part that shows courses upon login - this is where server responds with authentication required.

       

      $(document).on("pagebeforeshow",'#courselistpage', function(){

        $.ajax({

                      url: baseurl+ "/rest/courses" ,

                      method: 'GET',

                      contentType: 'application/json',

                      dataType: "json",

                      success: function (result) {

                          courselist=result;

                          for(var ii=0; ii<courselist.length; ii++){

       

       

        $('.courselistview').append('<li><a href="#" onclick="courselistclick('+ courselist[ii].id+','+courselist[ii].name+')">'+ courselist[ii].name +'</a></li>');

          $('.courselistview').listview('refresh');

          }

                      }, error: function (e) {

                          alert(JSON.stringify(e));

                      }

                  });

        // courselist=[{'id':1, "name": "course1"}, {'id':2, "name":'course2'}, {'id':3, 'name': 'course3'}];

         

      });

       

      Do I need to explicitly mention JSESSIONID in the second request? or is there a way to work around this in anyway? everything is tested successfully when I test using Postman.

       

       

      this is a screenshot of the "401 authentication required" I response I receive from the server when I ask for a list of courses.

       

      Capture.JPG