title: How to provide a secure authorization with ajax?
body: <p>The backend team provided me a POST call to create a new user account similar to the one in the snippet with an encrypted Authorization string in the header. How can the service be protected from violations, e.g. somebody could write a script and run it as a loop in the Chrome Browser console to call the service. The Authorization string is hardcoded in the frontend and requests a bearer token to create the account in a second server call. What would be a safer approach?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>fetch('https://jsonplaceholder.typicode.com/posts', {
    method: 'POST',
    body: JSON.stringify({
      title: 'New Account',
      body: 'Create account for new user',
      userId: 1
    }),
    headers: {
      'Content-type': 'application/json; charset=UTF-8',
        Authorization: `B dGhN4787496087493c87nR67faaf1dGS3g=`,
        AuthorizationHash: `B e9267f8a4709171e849e54aaf1db7319c`,    
    }
  })
  .then(res =&gt; res.json())
  .then(console.log)</code></pre>
  </div>
  </div>
  </p>