I have enabled the CSRF in the java back-end (in SecurityConfig.java file) due to maintain user sessions between the angular2 and spring app. but when the post submission fired, I haven't seen any CSRF token binded to the POST request.
How would be possible way to add the CSRF token to my angular2 app. (add to the post request )
loginService.ts
userLogin(loginDTO){
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
var result = this._http.post(this._rest_service_login, JSON.stringify(loginDTO),options)
.map(res => res.json());
return result;
}
You should have a look at the developer guide of Angular2. You can implement a strategy (or use an existing one) by using providers.
@NgModule({
(...)
providers:
[
{ provide: XSRFStrategy, useValue: new CookieXSRFStrategy('myCookieName', 'My-Header-Name')},
]
})
export class AppModule { }
bootstrap(
AppComponent,
[
{ provide: XSRFStrategy, useValue: new CookieXSRFStrategy('myCookieName', 'My-Header-Name')},
]
);
You can also implement a custom strategy for your application by using the following provider { provide: XSRFStrategy, useClass: MyXSRFStrategy}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With