title: OAUTH2.0 Automation
body: <p>I want to automate the generation of OAUTH2.0 access_token in prescript. The script that I have written gives me a 401 response. I need to know what am I doing wrong here. 
  <a href="https://i.stack.imgur.com/fuP1Y.png" rel="nofollow noreferrer">See The picture</a></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>var tokenUrl = pm.environment.get('requrl');
  var clientId = pm.environment.get('clientId');
  var clientSecret = pm.environment.get('secret');
  var scope = pm.environment.get('scope')
  var username = pm.environment.get('Username')
  var password = pm.environment.get('password')
  
  var getTokenRequest = {
      method: 'POST',
      url: tokenUrl,
      auth: {
          type: "basic",
          basic: [
              { key: "username", value: clientId },
              { key: "password", value: clientSecret }
          ]
      },
      body: {
          mode: 'urlencoded',
          formdata: [
              { key: 'grant_type', value: 'password' },
              { key: 'username', value: username},
              { key: 'password', value: password},
              { key: 'scope', value: scope}
          ]
      }
  };
  
  pm.sendRequest(getTokenRequest, (err, response) =&gt; {
      var jsonResponse = response.json(),
          token = jsonResponse.access_token;
      pm.environment.set("token", token);
  });</code></pre>
  </div>
  </div>
  </p>