@@ -31,7 +31,8 @@ export interface IHttpOptions {
3131 url : string
3232 alwaysUseGet ?: boolean
3333 headers : {
34- sessionID ?: string
34+ sessionID ?: string ,
35+ 'X-XSRF-TOKEN' ?: string ,
3536 apiKey ?: string
3637 }
3738}
@@ -305,6 +306,7 @@ export class Api {
305306 return new Promise ( ( resolve , reject ) => {
306307 this . request ( 'logout' , null , null , Api . Methods . GET ) . then ( ( result ) => {
307308 if ( result && result . success ) {
309+ delete this . _httpOptions . headers [ 'X-XSRF-TOKEN' ]
308310 delete this . _httpOptions . headers . sessionID
309311 resolve ( )
310312 } else {
@@ -414,8 +416,9 @@ export class Api {
414416 headers . append ( 'X-Requested-With' , 'XMLHttpRequest' )
415417 if ( this . _httpOptions . headers . sessionID ) {
416418 headers . append ( 'sessionID' , this . _httpOptions . headers . sessionID )
417- }
418- else if ( this . _httpOptions . headers . apiKey ) {
419+ } else if ( this . _httpOptions . headers [ 'X-XSRF-TOKEN' ] ) {
420+ headers . append ( 'X-XSRF-TOKEN' , this . _httpOptions . headers [ 'X-XSRF-TOKEN' ] )
421+ } else if ( this . _httpOptions . headers . apiKey ) {
419422 headers . append ( 'apiKey' , this . _httpOptions . headers . apiKey )
420423 }
421424
@@ -507,6 +510,20 @@ export class Api {
507510 }
508511 }
509512
513+ /**
514+ * Sets a 'X-XSRF-TOKEN' in the headers or removes 'X-XSRF-TOKEN' if passed argument is undefined
515+ * @memberOf Api
516+ * @param {String|undefined } X-XSRF-TOKEN X-XSRF-TOKEN to set
517+ */
518+ setXSRFToken ( xsrfToken ) {
519+ if ( xsrfToken ) {
520+ this . _httpOptions . headers [ 'X-XSRF-TOKEN' ] = xsrfToken
521+ }
522+ else {
523+ delete this . _httpOptions . headers [ 'X-XSRF-TOKEN' ]
524+ }
525+ }
526+
510527 /**
511528 * Starting from version 2.0 API allows users to upload files.
512529 * The server will return the JSON data which includes 'handle' of uploaded file.
0 commit comments