I am using Laravel as backend and JWT library (https://github.com/tymondesigns/jwt-auth ) integrated in it. In the backend, on the every request the laravel responds with new token attached in response header like
Authorization: Bearer <token>
here i am implementing front end in angular js Framework, and i intercept every request using a interceptor,
angular.module('Authentication')
.factory('httpRequestInterceptor',['$cookieStore','$location',
function($cookieStore,$location) {
return {
request: function(config) {
var currenUser = $cookieStore.get("globals");
if(currenUser)
{
var token = currenUser.currentUser.token;
if(token)
{
config.headers['Authorization'] = 'Bearer ' + token;
}
}else{
$location.path('/login');
}
console.log(config);
return config;
} ,
'response': function(response) {
console.log(response.headers()); // no authorization header i get,
//but when i console, in the network i can see the authorization header token
//here i have to access the response header
//but i can't get authorization bearer from header
//if i get the value of token i can replace the currant cookie token value with this response token
console.log(response);
return response;
}
}
}]);
php laravel 5.4 web.php
Route::group(['middleware' => ['jwt.auth', 'jwt.refresh']], function() {
Route::get('profile', [
'as' => 'auth.getAuthenticatedUser',
'uses' => 'AuthController@getAuthenticatedUser'
]);
Route::post('logout', 'Api\AuthController@logout');
});
In first time the token is pass from jwt library in body part. It is stored in cookies, in the subsequent request the token passes via Header.
The server responds back to client with generated token via header,after that i have to replace the cookie token value.
Here is the problem i get, i can't access the response header information by the interceptor response. How can i achieve it? Any response is appreciated. Thanks.