my message is based on this message http://stackoverflow.com/questions/26748106/how-to-manage-authentication-with-token-in-angular-js I have a backend with PHP5(Symfony2) and a front end with (angularJS) I have succeeded to create tokens with the backend,but I got a problem with angularjs,I have to get the token from the URL and to put it in every request to get client lists per example,this is what I did:
the controller:signin.js
'use strict';
// signin controller
app.controller('SigninFormController', ['$scope','$http', '$state','$localStorage','authorizationInterceptor', function($scope, $http, $state,$localStorage,authorizationInterceptor) {
$scope.user = {};
$scope.authError = null;
$scope.login = function() {
$scope.authError = null;
// Try to login
$http({method: 'POST', url: 'myURL/oauth/v2/token?client_id=clientID&client_secret=clientSecret&grant_type=client_credentials'})
.success(function(response){
if (response.data.user) {
$scope.errors.splice(0, $scope.errors.length);
$scope.msgs.splice(0, $scope.msgs.length);
$scope.posts = data; // response data
var token = this.$window.sessionStorage($scope.posts.access_token);
console.log(""+token);
console.log("success");
$state.go('app.home');}
})
.error(function(data, status, headers, config) {
$scope.authError = 'Email or Password not right';
console.log("data error ...");
});
};
and my services :access-services.js
.factory('Security', ['$http', function ($http) {
var token;
function login(email, password) {
return $http.post('/auth/login', {email: email, password: password})
.then(function (response) {
if (response.data.token) {
token=response.data.token;
}
});
}
function getToken(){
return token;
}
return {
login:login,
token:getToken
}; }])
.factory('authorizationInterceptor', ['Security', function (Security) {
return {
request: function (config) {
var token=Security.getToken();
config.headers = config.headers || {};
if (token) {
config.headers.Authorization = 'Bearer ' + token;
}
return config;} }; }]);
but this is what I get in console:

thanks for help