title: Authorization when creating a file in Javascript in a GitHub repo using API
body: <p>My goal is to create a static page with GitHub Pages with a simple button.</p>
  <p>When I press this button, I want to create a file in the same repository, in the same branch used for GitHub pages.</p>
  <p>I read something about Authorization Token to be used in the fetch request to create the file, so I created my Token, I put it into the index.html of the GitHub pages I'm using to access the repository.</p>
  <p>Very soon I received an email from GitHub telling me this token is revoked.</p>
  <p>The policy is described here: <a href="https://github.blog/2015-02-05-keeping-github-oauth-tokens-safe/" rel="nofollow noreferrer">https://github.blog/2015-02-05-keeping-github-oauth-tokens-safe/</a></p>
  <p>My question now is: how can I accomplish this task?</p>
  <p>The snippet I was using is the following:</p>
  <pre><code>async function createNewFileFunction() {
      const user =  { name:  'XXX', surname:  'YYY'  };
      const token = 'ghp_abcdefghijklmnopqrstuvwxyz1234567890';
      const api_url = &quot;https://api.github.com/repos/my_account/my_repo/contents/test.txt?ref=gh-pages&quot;;
      
      try {
          const response = await fetch(api_url, {
                                                     method: 'POST',
                                                     headers: {
                                                                   'Authorization': `token ${token}`,
                                                                   'Content-Type': 'application/json;charset=utf-8'
                                                              }, 
                                                     body: JSON.stringify(user)
                                                 }
                                              );
          console.log(await response.json());
          } catch (error) {
              console.log('Request Failed', error);
          }
      }
  </code></pre>