Results 1 to 2 of 2

Thread: How to get and add CSRF tokens in extjs's .js files.

  1. #1
    Sencha User
    Join Date
    Nov 2017
    Posts
    3
    Answers
    1
    Vote Rating
    0
      0  

    Default Answered: How to get and add CSRF tokens in extjs's .js files.

    In my application i have both JSP and JS using Ext JS 5.1. I need to apply spring csrf protection to my application. In Jsp i was able to add it as below :
    <body>
    <inputtype="hidden"name="${_csrf.parameterName}"value="${_csrf.token}">
    </body>But i am not sure how to do it in .js files? Do i have declare Meta tag for ext js too? I need to apply the csrf token to every ajax request.
    Just to highlight, i have scanned many sites but did not got any proper explanation or working example. How to add csrf in ajax calls of Ext js .js file ?

    I have gone through https://www.sencha.com/forum/showthread.php?273967
    But it does not give how to do the same?

  2. Ext.Ajax.on('beforerequest',function(conn, options){
    var x = document.getElementsByTagName("META");
    var token ="";
    var headerVal ="";
    var i;
    for(i =0; i < x.length; i++){
    if(x[i].name =="_csrf")
    {
    token
    = x[i].content;
    }elseif(x[i].name=="_csrf_header"){
    headerVal
    = x[i].content;
    }
    }

    Ext.Ajax.setDefaultHeaders({
    headerVal
    : token
    });
    });

  3. #2
    Sencha User
    Join Date
    Nov 2017
    Posts
    3
    Answers
    1
    Vote Rating
    0
      0  

    Default

    Ext.Ajax.on('beforerequest',function(conn, options){
    var x = document.getElementsByTagName("META");
    var token ="";
    var headerVal ="";
    var i;
    for(i =0; i < x.length; i++){
    if(x[i].name =="_csrf")
    {
    token
    = x[i].content;
    }elseif(x[i].name=="_csrf_header"){
    headerVal
    = x[i].content;
    }
    }

    Ext.Ajax.setDefaultHeaders({
    headerVal
    : token
    });
    });

Similar Threads

  1. CSRF Protection (CodeIgniter + EXTJS 5) - How To?
    By Carlos Souza in forum Ext 5: Q&A
    Replies: 2
    Last Post: 16 Aug 2015, 8:29 PM
  2. extjs rest and csrf
    By pedwards in forum Ext 5: Q&A
    Replies: 1
    Last Post: 1 Oct 2014, 10:52 AM
  3. Django 1.3 Login with ExtJS 4 and CSRF
    By aldolmx in forum Ext: Discussion
    Replies: 4
    Last Post: 26 Aug 2013, 12:34 AM
  4. How to insert csrf token into extjs form?
    By da_sweetp in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 30 Mar 2011, 3:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •