通过Restangular发送oauth access_token

时间:2014-05-07 13:31:18

标签: javascript angularjs oauth

我正在使用带有Restangular的Angular 1.2。在用户获得授权后,我需要设置头文件access_token,从那时起,每个请求都需要发送此头文件。我试着这样做:

angular.module('controllers', [])

.controller('Login', function($scope, Restangular) {

$scope.signin = {};

$scope.submitSignin = function() {
            var signin = Restangular.all('oauth/access_token');
            oauthPost = {
                grant_type: 'password',
                client_id: 'some_id',
                client_secret : 'some_secret_code',
                username: $scope.signin.email,
                password: $scope.signin.password
            };
            signin.post(oauthPost).then(function(data) {
                Restangular.setDefaultHeaders({accept: 'application/json',access_token: "somelongstring"});
            }, function() {
                console.log("There was an error.");
            });

        };

})

1 个答案:

答案 0 :(得分:0)

为我工作:

$http.defaults.headers.common['Authorization'] = 'Bearer ' + token;