【问题标题】:Sending oauth access_token via Restangular通过 Restangular 发送 oauth access_token
【发布时间】:2015-03-29 02:09:21
【问题描述】:

我正在使用带有 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.");
            });

        };

})

【问题讨论】:

    标签: javascript angularjs oauth


    【解决方案1】:

    为我工作:

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

    【讨论】:

      猜你喜欢
      • 2015-03-31
      • 1970-01-01
      • 2020-12-08
      • 1970-01-01
      • 2020-02-28
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多