title: How can i get csrf token in html meta tags using spring boot
body: <p>How can i get csrf token in html meta tags using spring boot?</p>
  
  <blockquote>
    <p>I already done the CSRF token in SPRING by using xml configuration</p>
  </blockquote>
  
  <p>Currently my project is in SPRING BOOT. I tried a lot but no luck.</p>
  
  <p>I have an html code</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Welcome to Spring Boot project&lt;/title&gt;
          &lt;meta name="_csrf" content="${_csrf.token}"/&gt;
          &lt;meta name="_csrf_header" content="${_csrf.headerName}"/&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="LoginPanel"&gt;
              &lt;form role="form" action="LoginAuth"&gt;
                  &lt;input value="sample" type="text" name="Username" class="form-control" data-parsley-type="alphanum" placeholder="Username" required/&gt;
                  &lt;button type="submit" class="btn-block Signin btn btn-labeled1 btn-warning"&gt;
                      Sign in
                  &lt;/button&gt;
              &lt;/form&gt;
          &lt;/div&gt;
          &lt;script&gt;
          $(document).ready(function()
          {
              var Form = $(".LoginPanel").find("form");
              $(".LoginPanel").find("button.Signin").click(function(Event)
              {       
                  Event.preventDefault();
                  $.ajax(
                  {
                      type: "POST",
                      url: "LoginAuth",
                      data: Form.serialize(),
                      beforeSend: function (xhr,settings)
                      {
                          var CSRFToken = $("meta[name='_csrf']").attr("content");console.log(CSRFToken);
                          var CSRFHeader = $("meta[name='_csrf_header']").attr("content");console.log(CSRFHeader);
                          xhr.setRequestHeader(CSRFHeader, CSRFToken);
                      },
                      success: function(ResponseData, textStatus, jqXHR)
                      {
                          console.log(ResponseData);alert("success");
                      },
                      error: function(jqXHR, textStatus, errorThrown)
                      {
                          console.log("Error");
                      }
                  });
              });
          });
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My security config is </p>
  
  <pre><code>@EnableWebSecurity
  @Configuration
  public class WebSecurityConfig extends
     WebSecurityConfigurerAdapter {
  
    @Override
    protected void configure(HttpSecurity http) throws Exception {
      http
        .csrf();
    }
  }
  </code></pre>
  
  <p>application.properties</p>
  
  <pre><code>security.basic.enabled=false
  security.enable-csrf=true
  </code></pre>
  
  <p>After run the project, still i get the the null token &amp; header name</p>
  
  <p>I expected from the page source like this</p>
  
  <pre><code>&lt;meta name="_csrf" content="7d789af1-996f-4241-ab70-2421da47bb09"/&gt;
  &lt;meta name="_csrf_header" content="X-XSRF-TOKEN"/&gt;
  </code></pre>
  
  <p>Is it possible?</p>
  
  <p>Thanks</p>