locked
How to handle the back to app button in webauthentication broker class?

    Question

  • I am using the webauthentication broker class for the facebook. This works fine when the internet is available but when the internet is not available then a network connection message is displayed to the user . This is fine but when the user clicks on the back to app button ,an error occurs. I tried with WebAuthenticationBroker sample from msn as well the sample also throws the same error.Following is my code.

     Windows.Security.Authentication.Web.WebAuthenticationBroker.authenticateAsync(
                Windows.Security.Authentication.Web.WebAuthenticationOptions.none, startURL, endURL).done(
    
                function (result) {
                    var feedData = '';
                    //To separate the access token from the retuned result
                    if (result.responseData) {
                        var tokenIndex = result.responseData.indexOf("access_token=");
                        var expIndex = result.responseData.indexOf("&expires_in");
                        if (tokenIndex != -1 && expIndex != -1) {
                            accessToken = result.responseData.substring(tokenIndex, expIndex);
                            var applicationData = Windows.Storage.ApplicationData.current;
                            var fb_exchange_token = accessToken.split('=');
                            var extending_access = "https://graph.facebook.com/oauth/access_token?client_id=246492832126935&client_secret=488079a31a9c68f150925ada55d7524d&grant_type=fb_exchange_token&fb_exchange_token=";
                            extending_access += fb_exchange_token[1];
    
                            WinJS.xhr({ type: "GET", url: extending_access }).then(function (resp) {
                                var extentded_token = resp.responseText;
                                var expIndex = resp.responseText.split("&exp");
                                accessToken = expIndex[0];
                            }, function (err) {
                                var error = err;
                            });
                            applicationData.localSettings.values["access_token"] = accessToken;
                            //document.getElementById("divLogoutContent").style.visibility = "hidden";
                            //getData(accessToken);
                            if (result.responseStatus === Windows.Security.Authentication.Web.WebAuthenticationStatus.errorHttp) {
                                document.getElementById("FacebookDebugArea").value += "Error returned: " + result.responseErrorDetail + "\r\n";
                            }
                            
                               
                           
                        }
                    }
                }, function (err) {
                    Windows.Storage.ApplicationData.current.localSettings.values["access_token"] = null;
                    authzInProgress = null;
                    launchFacebookWebAuth();
                });
    The error function was called on clicking the bact to app button when I was doing it in visual studio 2011. But when I checked the same with visual studio 2012 its throwing an error.
    Wednesday, August 01, 2012 5:32 AM

Answers

  • Hi Regel,

    You should handle it by catching the error and displaying an in-line error message to the user.

    -Jeff


    Jeff Sanders (MSFT)

    Monday, August 06, 2012 3:55 PM
    Moderator