清除Phonegap的InAppBrowser缓存

时间:2015-11-20 08:59:17

标签: javascript cordova caching inappbrowser

我在我的应用中使用Google授权。它运作完美, 但问题是当有人从应用程序注销时缓存不清楚。

我尝试添加clearcache=yesclearsessioncache=yes,但他们似乎没有做任何事情。当有人尝试重新登录时,如果没有清除缓存,则使用先前登录的帐户验证令牌。

有没有办法可以删除与InAppBrowser相关的所有内容?

 var googleapi = {
    authorize: function (options) {
        var deferred = $.Deferred();

        //Build the OAuth consent page URL
        var authUrl = 'https://accounts.google.com/o/oauth2/auth?' + $.param({
            client_id: options.client_id,
            redirect_uri: options.redirect_uri,
            response_type: 'code',
            scope: options.scope

        });

 var authWindow = window.open(authUrl,'_blank','location=no,toolbar=no,clearsessioncache=yes');

        $(authWindow).on('loadstart', function (e) {
            var url = e.originalEvent.url;
            var code = /\?code=(.+)$/.exec(url);
            var error = /\?error=(.+)$/.exec(url);

            if (code || error) {
                //Always close the browser when match is found
                authWindow.close();
            }

            if (code) {
                //Exchange the authorization code for an access token
                $.post('https://accounts.google.com/o/oauth2/token', {
                    code: code[1],
                    client_id: options.client_id,
                    client_secret: options.client_secret,
                    redirect_uri: options.redirect_uri,
                    grant_type: 'authorization_code'
                }).done(function (data) {
                    deferred.resolve(data);

                    $("#loginStatus").html('Name: ' + data.given_name);
                }).fail(function (response) {
                    deferred.reject(response.responseJSON);
                });
            } else if (error) {
                //The user denied access to the app
                deferred.reject({
                    error: error[1]
                });
            }
        });

        return deferred.promise();
    }
};
var accessToken;
var UserData = null;
function callGoogle() {

    googleapi.authorize({
        client_id: 'client_id',
        client_secret: 'client_secret-key',
        redirect_uri: 'http://localhost',
        scope: 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email'
    }).done(function (data) {
        accessToken = data.access_token;
        getDataProfile();
    });

}
function getDataProfile() {
    var term = null;       
    $.ajax({
        url: 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + accessToken,
        type: 'GET',
        data: term,
        dataType: 'json',
        error: function (jqXHR, text_status, strError) {
        },
        success: function (data) {
            var item;
            var OAuthToken = accessToken;
            var OAuthAccessToken = data.id;
            var username = data.email;
            var firstname = data.given_name;
            var lastname = data.family_name;
            var ExternalIdentifier = data.id;
            var Email = data.email;
            var ProviderSystemName = "ExternalAuth.Google";

            ExternalResponseInsert(apiSecretKey, storeId, languageId, username, firstname, lastname, Email, ExternalIdentifier, OAuthToken, OAuthAccessToken, ProviderSystemName);
        }
    });
    //disconnectUser();
}
function disconnectUser() {
    var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' + accessToken;

    $.ajax({
        type: 'GET',
        url: revokeUrl,
        async: false,
        contentType: "application/json",
        dataType: 'jsonp',
        success: function (nullResponse) {
          accessToken = null;
            console.log(JSON.stringify(nullResponse));
            console.log("-----signed out..!!----" + accessToken);
        },
        error: function (e) {
            // Handle the error

        }
    });
}

0 个答案:

没有答案