locked
Azure Mobile Login Problem in PhoneGap app RRS feed

  • Question

  • Hi,

    I have created a Microsoft App login account and I get the following message in Android App (build using PhoneGap).

    Error message:

     

         "Login is only support from http:// and https:// URLs. Please host your page in a web server."

     

    Here is my Azure Mobile Login Script:

    function insert(item, user, request) {
        item.userId = user.userId;
        request.execute();
    
    }

    Here is my JS code:

    $(function() {
        var client = new WindowsAzure.MobileServiceClient('https://XXXXXXXXXXXX.azure-mobile.net/', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
            todoItemTable = client.getTable('todoitem');
    
        // Read current data and rebuild UI.
        // If you plan to generate complex UIs like this, consider using a JavaScript templating library.
        function refreshTodoItems() {
            var query = todoItemTable.where({ complete: false });
    
            query.read().then(function(todoItems) {
                var listItems = $.map(todoItems, function(item) {
                    return $('<li>')
                        .attr('data-todoitem-id', item.id)
                        .append($('<button class="item-delete">Delete</button>'))
                        .append($('<input type="checkbox" class="item-complete">').prop('checked', item.complete))
                        .append($('<div>').append($('<input class="item-text">').val(item.text)));
                });
    
                $('#todo-items').empty().append(listItems).toggle(listItems.length > 0);
                $('#summary').html('<strong>' + todoItems.length + '</strong> item(s)');
            });
        }
    
        function getTodoItemId(formElement) {
            return Number($(formElement).closest('li').attr('data-todoitem-id'));
        }
    
        // Handle insert
        $('#add-item').submit(function(evt) {
            var textbox = $('#new-item-text'),
                itemText = textbox.val();
            if (itemText !== '') {
                todoItemTable.insert({ text: itemText, complete: false }).then(refreshTodoItems);
            }
            textbox.val('').focus();
            evt.preventDefault();
        });
    
        // Handle update
        $(document.body).on('change', '.item-text', function() {
            var newText = $(this).val();
            todoItemTable.update({ id: getTodoItemId(this), text: newText });
        });
    
        $(document.body).on('change', '.item-complete', function() {
            var isComplete = $(this).prop('checked');
            todoItemTable.update({ id: getTodoItemId(this), complete: isComplete }).then(refreshTodoItems);
        });
    
        // Handle delete
        $(document.body).on('click', '.item-delete', function () {
            todoItemTable.del({ id: getTodoItemId(this) }).then(refreshTodoItems);
        });
    
     // On initial load, start by fetching the current data=====================================
        function refreshAuthDisplay() {
            var isLoggedIn = client.currentUser !== null;
            $("#logged-in").toggle(isLoggedIn);
            $("#logged-out").toggle(!isLoggedIn);
    
            if (isLoggedIn) {
                $("#login-name").text(client.currentUser.userId);
                refreshTodoItems();
            }
        }
    
        //microsoftaccount,facebook, twitter, or google.
        function logIn() {
            client.login("microsoftaccount").then(refreshAuthDisplay, function (error) {
                alert(error);
            });
    
        }
    function logOut() {
            client.logout();
            refreshAuthDisplay();
            $('#summary').html('<strong>You must login to access data.</strong>');
        }
    
    
        // On page init, fetch the data and set up event handlers
        $(function () {
            refreshAuthDisplay();
            $('#summary').html('<strong>You must login to access data.</strong>');
            $("#logged-out button").click(logIn);
            $("#logged-in button").click(logOut);
        });
    
    });

    The above error does not appear on Desktop browser login (only on Android App). Can you tell what I need to do to fix this.

     

    Thanks.






    Monday, April 15, 2013 5:02 PM

Answers

  • If you followed that post it tells you to include the Cordova library.  If you did that and it still does not work, I will need to get your project to repro the issue.

    Can you post it to SkyDrive?

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by jameslcs Tuesday, April 16, 2013 8:43 PM
    Tuesday, April 16, 2013 2:13 PM

All replies

  • Hi James,

    We don't have any sample yet for phonegap but check out this post:

    http://social.msdn.microsoft.com/Forums/en-US/azuremobile/thread/a2386093-73cd-44fb-a418-4fa83a36c800

    -Jeff


    Jeff Sanders (MSFT)

    Monday, April 15, 2013 6:37 PM
  • I have read that post before, do as instructed  and everything works well except for using authorization provider (e.g. Google, Facebook, Microsoft...) that give me this error message in mobile device:

         "Login is only support from http:// and https:// URLs. Please host your page in a web server."

    Note, i don't have any error and able to use the authorization provider and login in a desktop browser but not on a mobile device.

    Any idea why?

    thanks.

    Monday, April 15, 2013 11:00 PM
  • If you followed that post it tells you to include the Cordova library.  If you did that and it still does not work, I will need to get your project to repro the issue.

    Can you post it to SkyDrive?

    -Jeff


    Jeff Sanders (MSFT)

    • Marked as answer by jameslcs Tuesday, April 16, 2013 8:43 PM
    Tuesday, April 16, 2013 2:13 PM
  • very good, i'm able to do authorization in my mobile device, now. Thanks for telling me to include Cordova lib.

    btw how do you know i didn't include it? :-)  i guess it must comes with the job. :-)

    thanks man,


    • Edited by jameslcs Tuesday, April 16, 2013 8:43 PM
    Tuesday, April 16, 2013 8:43 PM
  • I'm having the exact issue still...  even after explicit js includes.

    html snip:

    <head>
      ...
      <script type="text/javascript" src='https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.0.min.js'></script>
      <script src="https://mymobi.azure-mobile.net/client/MobileServices.Web-1.0.0.min.js"></script>
      <script src="js/libs/cordova-2.6.0.js"></script>
    </head>

    js snip:

    client.login("google").then(function() {
      var blah = client.getTable("blah").read().then(function(data) {
    				console.log(data);
    			});
    			
    			console.log(blah);
    		}, function(error) {
    			console.log(error);
    		});

    LogCat still spits out Login is only supported from http:// or https:// URLs.  I read through the other post several times.

    Sunday, May 5, 2013 11:34 PM
  • Try this:

    http://blogs.msdn.com/b/jpsanders/archive/2013/04/17/phonegap-and-windows-azure-mobile-services-error-login-is-only-supported-from-http-and-https-urls-please-host-your-page-in-a-web-server.aspx

    and let me know if it helps!

    -Jeff


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Monday, May 6, 2013 12:43 PM
  • Hi,

      I have tried the workaround, and still get the error with phonegap 3.x.

    This thread on stackoverflow aluded to a phonegap 3.x incompatibility with the mobile service, I am not sure at this point:

    http://stackoverflow.com/questions/20706197/phonegap-3-3-and-mobile-services-html-app-on-android

    Thanks for any suggestions.

    Also when will the documentation and updates mentioned in the blog post released/posted.

    Thanks

    Thursday, January 2, 2014 9:28 PM
  • It appears this is still an issue.  Has anyone found a fix yet?

    Wednesday, March 5, 2014 5:21 AM
  • Which issue are you talking about?  There are several things in this post.  Perhaps you should start a new post with all the pertinent information.

    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Wednesday, March 5, 2014 1:28 PM