title: WP-API Retrieving Drafts "Cookie nonce is invalid"
body: <p>I'm working on a front-end app which ties into wordpress API which sits on a seperate domain.</p>
  
  <p>I'm wanting to retrieve a post draft so when the user clicks "Preview Post" in the wordpress admin panel, it opens my app with the correct content.</p>
  
  <p>I'm loading some Javascript into the WP Admin so I can amend all "Preview Post" links in the admin panel with a wp_nonce token for authentication purposes. This is done using the below snippet, which tweaks the preview post link into for example: <code>http://example.com/blog?p=127&amp;preview=true&amp;auth=16045802ee</code></p>
  
  <pre><code>function admin_inline_js(){
  
      // Grab URL 
      echo '
      &lt;script&gt;
      document.addEventListener("DOMContentLoaded", function() {
          // Grab all preview anchors
          var anchors = document.querySelectorAll("a[href*=\'preview=true\']"), i;
          // Loop through and amend to remove the trailing slash, as WP doesnt provide any easy method to achieve this.
          for(i = 0; i &lt; anchors.length; i++) {
              anchors[i].href = anchors[i].href.replace("blog/", "blog") + \'&amp;auth=' . wp_create_nonce('wp_rest') .'\';
          }
      });
      &lt;/script&gt;
      ';
  }
  add_action( 'admin_print_scripts', 'admin_inline_js' );
  </code></pre>
  
  <p>At <code>http://example.com/blog?p=127&amp;preview=true&amp;auth=16045802ee</code>, the <code>auth</code> parameter is then used to post a request back to wordpress to retrieve the draft with an ID of 127, with a nonce token of <code>16045802ee</code>. However this isn't working, and I'm getting this response:</p>
  
  <pre><code>object(stdClass)#459 (3) { ["code"]=&gt; string(25) "rest_cookie_invalid_nonce" ["message"]=&gt; string(23) "Cookie nonce is invalid" ["data"]=&gt; object(stdClass)#532 (1) { ["status"]=&gt; int(403) } }
  </code></pre>
  
  <p>Can anybody spot what I'm doing wrong here? :/</p>
  
  <p>Thanks.</p>