One of the option to store JWT at client side could be window.localStorage which stores data with no expiration date.
And after that, with each $http request(in Authentication header) you send this token to the server using Interceptor like following,
angular.module('myApp').factory('authInterceptor', ['$q', function ($q) {
return {
request: function (config) {
config.headers = config.headers || {};
if (config.headers.skipAuthorization === false) {
var token = localStorage.getItem('authenticationToken');
if (token != null) {
config.headers.Authorization = token;
}
}
return config;
},
response: function (response) {
if (response.headers("Authorization") != undefined || response.headers("Authorization") != '') {
localStorage.setItem('authenticationToken', response.headers("Authorization"));
}
return response;
},
responseError: function (rejection) {
if (rejection.status === "401") {
localStorage.removeItem('authenticationToken');
}
return $q.reject(rejection);
}
};
} ]);
angular.module('myApp').config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('authInterceptor');
} ]);
And with each request where you want this token to be sent to the server, set skipAuthorization:false in header as,
$http({
....
headers:{skipAuthorization:false}
}).then(....)
localStorage.setItem("jwt", angular.toJson(yourToken));