AngularJS Ionic $ http请求API维护身份验证数据

时间:2016-06-09 11:13:42

标签: android angularjs caching ionic-framework http-basic-authentication

我正在编写基于Ionic / Cordova的应用程序,该应用程序需要使用外部API,必须提供身份验证数据(通过http-basic标头)。

问题是应用程序维护授权(提供正确的凭据后)并且我无法注销(强制应用程序阻止访问API)。

HTTP身份验证验证机制:

var validateCredentials = function(user, password, callback) {

    var req = {
        method: 'GET',
        url: 'http://server.host.com/api/check?Accept=application/json',
         headers: {
            'Authorization': 'Basic ' + btoa(user + ':' + password)
         }
    };

    $http(req).success(function(data) {
        callback(true);
    }).error(function(error) {
        callback(false);
    });
}

我的用例:

1)我正在为方法提供错误的凭证并收到401(这是好的):

enter image description here

2)然后我提供正确的凭证并收到200 OK(这也很好):

enter image description here

3)最后,如果我再次提供错误的凭证,API仍然有效(200而不是401):

enter image description here

因此,我无法从我的应用程序退出,而且 - 我无法登录其他用户!

我试图用https://github.com/moderna/cordova-plugin-cache清除缓存,离子历史和webview缓存,但仍然没有成功。清除会话/身份验证数据的唯一选项是Andoird OS设置/应用程序/清除应用程序数据。

最后 - 在应用程序的上下文中没有cookie或会话变量(至少根据使用我的设备以调试模式运行的Chrome Developper控制台)。

任何提示都赞赏!

0 个答案:

没有答案
相关问题