Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用$resource使用AngularJS对第三方API进行的安全API调用_Javascript_Angularjs_Api - Fatal编程技术网

Javascript 使用$resource使用AngularJS对第三方API进行的安全API调用

Javascript 使用$resource使用AngularJS对第三方API进行的安全API调用,javascript,angularjs,api,Javascript,Angularjs,Api,我必须使用AngualrJS前端与基于PHP的API通信。我的资源结构如下: app.factory('Basket', ['$resource', '$http', function($resource, $http){ $http.defaults.headers.post["Content-Type"] = "text/plain"; return { newBasket: $resource(env + '/rest/v1/newbasket'),

我必须使用AngualrJS前端与基于PHP的API通信。我的资源结构如下:

app.factory('Basket', ['$resource', '$http', 
function($resource, $http){
    $http.defaults.headers.post["Content-Type"] = "text/plain";
    return { 
        newBasket: $resource(env + '/rest/v1/newbasket'),
        newLine: $resource(env + '/rest/v1/newbasketline'),
        removeBasketLine: $resource(env + '/rest/v1/removebasketline'),
        getBasketItems: $resource(env + '/rest/v1/getbasketlines/:hash', {hash: '@hash'}),
        getDbBasketIds: $resource(env + '/rest/v1/getbasketids/:hash', {hash: '@hash'})
    };   
}]);
API要求我在HTTP头HTTP\U APIKEY中传递令牌。我可以用这样的标题:

$http.defaults.headers.common['APIKEY'] = 'myapikey';
但是任何人都可以查看源代码来获取我的密钥,然后将其用于邪恶目的


我似乎找不到任何关于如何使用AngularJS安全地发送API访问令牌的建议,有什么想法吗?

这是所有SPA网站的常见情况-它们将数据存储在客户端,因此用户可以访问,与此无关。但您可以加密本地存储,如本问题中所述: