rest - CSRF : How to set cookie named XSRF-TOKEN in JAX-RS from backend to use with AngularJS in frontend -


my application uses angularjs in front end , java restful web services @ end. trying use xsrf-token prevent cross site request forgery.

on front end, have angular-cookies.js added, , included ngcookies dependency in 'module'.

angular.module('myapp.list', ['ngcookies'])  .controller('listctrl', ['$scope', '$http', '$location', function coilistctrl($scope, $http, $location) {    //some functions   }) .run(['$http', '$cookies', function($http, $cookies) { //check if header x-xsrf-token set angularjs console.log($http.defaults.headers.post['x-xsrf-token']);     debugger; }]); 

on front end unable see cookie have created on end in both below ways:

1

using httpservletresponse object, way i'm unsure how sent ui not using httpresponse.sendredirect(url);

@context httpservletresponse httpresponse; httpresponse.addcookie(new cookie("xsrf-token", string.valueof(math.random())); 

2

adding cookies responsebuilder return response using responsebuilder.build() method in typical jax-rs service

responsebuilder responsebuilder = response.temporaryredirect(new uri(redirecturl)); newcookie abc = new newcookie("xsrf-token", string.valueof(math.random())); responsebuilder.cookie(abc); return responsebuilder.build(); 

could please me create valid cookies , use them.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -