title: NodeJs 403 Provided Authentication is not valid for Resource AUTH HEADER ISSUE
body: <p>I am new to NodeJs and with some little NodeJs knowledge I wrote following code to basically get Access Token from Azure Tenant and later on use the same Access Token in the subsequent GET request thru AXIOS to query Azure Resource to which the Client ID Secret has been created (APP registration with Permission granted). I am able to get the Access Token but unfortunately the next GET request Fails with 403 and the same code works fine in Powershell, I am sure I am doing some small mistake in the Get Request header or some other config, Any help ? Following is the Node.Js code:-</p>
  
  <pre><code>const axios = require('axios');
  const oauth = require('axios-oauth-client');
  const qs = require('qs');
  const APP_ID = 'XXXXXXXXXXXXXX';
  const APP_SECERET = 'YYYYYYYYY';
  const TOKEN_ENDPOINT ='https://login.microsoftonline.com/MyTenantIDGUID/oauth2/token?api-version=1.0';
  const MS_GRAPH_SCOPE = 'Data.Read';
  const resource ='https://api.loganalytics.io';
  var responseval = "";
  
  const postData = {
      client_id: APP_ID,
      scope: resource,
      client_secret: APP_SECERET,
      grant_type: 'client_credentials'
    };
  
    axios.defaults.headers.post['Content-Type'] =
      'application/x-www-form-urlencoded';
  
      axios
      .post(TOKEN_ENDPOINT, qs.stringify(postData))
      .then(function(response){
          //console.log(response);
          responseval= 'Bearer ' + response.data.access_token;
          console.log ( responseval)
          //Instance created below now for Log Analytics calls and passing the Access Token
  
          var baseUrlLogAnl = 'https://api.loganalytics.io/v1/workspaces/MyLogAnalytisWorkspaceGUID/query?query=externalapistatus_CL';
          var config ={headers: { 'Authorization': responseval, 'Content-Type': 'application/json' }};
          axios.get(baseUrlLogAnl,config)
          .then(function(response){
              console.log (response)
          })
          .catch(function (err){
              console.log(err.response);
          }); 
      })
      .catch(function (err){
          console.log(err.response);
      });
  </code></pre>
  
  <p>After the execution of above code following is the RESULT and one THING STANDS OUT THAT THE AUTHORIZATION HEADER is MESSED UP with AXIO AGET and CONTENT-TYPE not sure how I can trim it:</p>
  
  <pre><code>Authorization:
           'Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKK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inWdzGXkLlH_BHvAKrYw',
          **'Content-Type': 'application/json',
          'User-Agent': 'axios/0.19.1'** },
  </code></pre>
  
  <p>Here is the FULL OUTPUT:-</p>
  
  <pre><code>Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZwQSJ9.eyJhdWQiOiJzcG46MDAwMDAwMDItMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvZmEwNjE5ODItYTgxMC00YjQ4LTg5OGYtZGYzZTc2MWNlNzI3LyIsImlhdCI6MTU3ODc1NTg5MCwibmJmIjoxNTc4NzU1ODkwLCJleHAiOjE1Nzg3NTk3OTAsImFpbyI6IjQyTmdZQWdzMjMvdkc3dk5pNTZVVS8zMkVScFNBQT09IiwiYXBwaWQiOiIyNTMyNWY1ZC0yMWI1LTRkMmYtYWE4Ny1jMjYyNmZlZjU2OGQiLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9mYTA2MTk4Mi1hODEwXXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZwLThmOGUtM2QyZGFhYzgzZDIzIiwidGVuYW50X3JlZ2lvbl9zY29wZSI6Ik5BIiwidGlkIjoiZmEwNjE5ODItYTgxMC00YjQ4LTg5OGYtZGYzZTc2MWNlNzI3IiwidXRpIjoiaXRxTU5FN3dRMG11aUdySDVzTlBBQSIsInZlciI6IjEuMCJ9.UoOWozRlYhrkQMzFEUGWZJxEueN_2TRlR96SmhZt5M03BRxpqzlazRXaqWAz8qnHQvSCWVdZZtV96UWU_mbMxIzoSnIBGCUvDphUMh0OIJNFTy3-xD6NgAAhhm904-7yF2mnLQu0dFq06DmTNMk0XXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZhMbhZeHs7D9U0Xi1Dcw6dHbwbfgn-zThudKTXVfxFxv0KakinWdzGXkLlH_BHvAKrYw
  { status: 403,
    statusText: 'Forbidden',
    headers:
     { date: 'Sat, 11 Jan 2020 15:20:33 GMT',
       'content-type': 'application/json; charset=utf-8',
       'content-length': '241',
       connection: 'close',
       'strict-transport-security': 'max-age=15724800; includeSubDomains',
       via: '1.1 draft-oms-6f46cfc587-khxdk',
       'x-content-type-options': 'nosniff',
       'access-control-allow-origin': '*',
       'access-control-expose-headers':
        'Retry-After,Age,WWW-Authenticate,x-resource-identities,x-ms-status-location',
       vary: 'Accept-Encoding' },
    config:
     { url:
        'https://api.loganalytics.io/v1/workspaces/MYWORKSPACEGUID/query?query=externalapistatus_CL',
       method: 'get',
       headers:
        { Accept: 'application/json, text/plain, */*',
          Authorization:
           'Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZwQSJ9.eyJhdWQiOiJzcG46MDAwMDAwMDItMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvZmEwNjE5ODItYTgxMC00YjQ4LTg5OGYtZGYzZTc2MWNlNzI3LyIsImlhdCI6MTU3ODc1NTg5MCwibmJmIjoxNTc4NzU1ODkwLCJleHAiOjE1Nzg3NTk3OTAsImFpbyI6IjQyTmdZQWdzMjMvdkc3dk5pNTZVVS8zMkVScFNBQT09IiwiYXBwaWQiOiIyNTMyNWY1ZC0yMWI1LTRkMmYtYWE4Ny1jMjYyNmZlZjU2OGQiLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9mYTA2MTk4Mi1hODEwXXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZwLThmOGUtM2QyZGFhYzgzZDIzIiwidGVuYW50X3JlZ2lvbl9zY29wZSI6Ik5BIiwidGlkIjoiZmEwNjE5ODItYTgxMC00YjQ4LTg5OGYtZGYzZTc2MWNlNzI3IiwidXRpIjoiaXRxTU5FN3dRMG11aUdySDVzTlBBQSIsInZlciI6IjEuMCJ9.UoOWozRlYhrkQMzFEUGWZJxEueN_2TRlR96SmhZt5M03BRxpqzlazRXaqWAz8qnHQvSCWVdZZtV96UWU_mbMxIzoSnIBGCUvDphUMh0OIJNFTy3-xD6NgAAhhm904-7yF2mnLQu0dFq06DmTNMk0XXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZhMbhZeHs7D9U0Xi1Dcw6dHbwbfgn-zThudKTXVfxFxv0KakinWdzGXkLlH_BHvAKrYw',
          'Content-Type': 'application/json',
          'User-Agent': 'axios/0.19.1' },
       transformRequest: [ [Function: transformRequest] ],
       transformResponse: [ [Function: transformResponse] ],
       timeout: 0,
       adapter: [Function: httpAdapter],
       xsrfCookieName: 'XSRF-TOKEN',
       xsrfHeaderName: 'X-XSRF-TOKEN',
       maxContentLength: -1,
       validateStatus: [Function: validateStatus],
       data: undefined },
    request:
     ClientRequest {
       _events:
        [Object: null prototype] {
          socket: [Function],
          abort: [Function],
          aborted: [Function],
          error: [Function],
          timeout: [Function],
          prefinish: [Function: requestOnPrefinish] },
       _eventsCount: 6,
       _maxListeners: undefined,
       output: [],
       outputEncodings: [],
       outputCallbacks: [],
       outputSize: 0,
       writable: true,
       _last: true,
       chunkedEncoding: false,
       shouldKeepAlive: false,
       useChunkedEncodingByDefault: false,
       sendDate: false,
       _removedConnection: false,
       _removedContLen: false,
       _removedTE: false,
       _contentLength: 0,
       _hasBody: true,
       _trailer: '',
       finished: true,
       _headerSent: true,
       socket:
        TLSSocket {
          _tlsOptions: [Object],
          _secureEstablished: true,
          _securePending: false,
          _newSessionPending: false,
          _controlReleased: true,
          _SNICallback: null,
          servername: 'api.loganalytics.io',
          alpnProtocol: false,
          authorized: true,
          authorizationError: null,
          encrypted: true,
          _events: [Object],
          _eventsCount: 8,
          connecting: false,
          _hadError: false,
          _handle: [TLSWrap],
          _parent: null,
          _host: 'api.loganalytics.io',
          _readableState: [ReadableState],
          readable: true,
          _maxListeners: undefined,
          _writableState: [WritableState],
          writable: false,
          allowHalfOpen: false,
          _sockname: null,
          _pendingData: null,
          _pendingEncoding: '',
          server: undefined,
          _server: null,
          ssl: [TLSWrap],
          _requestCert: true,
          _rejectUnauthorized: true,
          parser: null,
          _httpMessage: [Circular],
          [Symbol(res)]: [TLSWrap],
          [Symbol(asyncId)]: 27,
          [Symbol(lastWriteQueueSize)]: 0,
          [Symbol(timeout)]: null,
          [Symbol(kBytesRead)]: 0,
          [Symbol(kBytesWritten)]: 0,
          [Symbol(connect-options)]: [Object] },
       connection:
        TLSSocket {
          _tlsOptions: [Object],
          _secureEstablished: true,
          _securePending: false,
          _newSessionPending: false,
          _controlReleased: true,
          _SNICallback: null,
          servername: 'api.loganalytics.io',
          alpnProtocol: false,
          authorized: true,
          authorizationError: null,
          encrypted: true,
          _events: [Object],
          _eventsCount: 8,
          connecting: false,
          _hadError: false,
          _handle: [TLSWrap],
          _parent: null,
          _host: 'api.loganalytics.io',
          _readableState: [ReadableState],
          readable: true,
          _maxListeners: undefined,
          _writableState: [WritableState],
          writable: false,
          allowHalfOpen: false,
          _sockname: null,
          _pendingData: null,
          _pendingEncoding: '',
          server: undefined,
          _server: null,
          ssl: [TLSWrap],
          _requestCert: true,
          _rejectUnauthorized: true,
          parser: null,
          _httpMessage: [Circular],
          [Symbol(res)]: [TLSWrap],
          [Symbol(asyncId)]: 27,
          [Symbol(lastWriteQueueSize)]: 0,
          [Symbol(timeout)]: null,
          [Symbol(kBytesRead)]: 0,
          [Symbol(kBytesWritten)]: 0,
          [Symbol(connect-options)]: [Object] },
       _header:
        'GET /v1/workspaces/427fa6ee-41cd-4570-b201-ef6cda4bd314/query?query=externalapistatus_CL HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nAuthorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZwQSJ9.eyJhdWQiOiJzcG46MDAwMDAwMDItMDAwMC0wMDAwLWMwMDAtMDAwMDAwMDAwMDAwIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvZmEwNjE5ODItYTgxMC00YjQ4LTg5OGYtZGYzZTc2MWNlNzI3LyIsImlhdCI6MTU3ODc1NTg5MCwibmJmIjoxNTc4NzU1ODkwLCJleHAiOjE1Nzg3NTk3OTAsImFpbyI6IjQyTmdZQWdzMjMvdkc3dk5pNTZVVS8zMkVScFNBQT09IiwiYXBwaWQiOiIyNTMyNWY1ZC0yMWI1LTRkMmYtYWE4Ny1jMjYyNmZlZjU2OGQiLCJhcHBpZGFjciI6IjEiLCJpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9mYTA2MTk4Mi1hODEwXXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZwLThmOGUtM2QyZGFhYzgzZDIzIiwidGVuYW50X3JlZ2lvbl9zY29wZSI6Ik5BIiwidGlkIjoiZmEwNjE5ODItYTgxMC00YjQ4LTg5OGYtZGYzZTc2MWNlNzI3IiwidXRpIjoiaXRxTU5FN3dRMG11aUdySDVzTlBBQSIsInZlciI6IjEuMCJ9.UoOWozRlYhrkQMzFEUGWZJxEueN_2TRlR96SmhZt5M03BRxpqzlazRXaqWAz8qnHQvSCWVdZZtV96UWU_mbMxIzoSnIBGCUvDphUMh0OIJNFTy3-xD6NgAAhhm904-7yF2mnLQu0dFq06DmTNMk0XXXXXXXXXXXXXXXXXXXXXXXXXXXXKKKKKKKKKKKKKKKKKKKKKKKKKKKSSSSSSSSSSSSSSSSSSSSSSSSZZZZZZZZZZZZZZZZZZZZhMbhZeHs7D9U0Xi1Dcw6dHbwbfgn-zThudKTXVfxFxv0KakinWdzGXkLlH_BHvAKrYw\r\nContent-Type: application/json\r\nUser-Agent: axios/0.19.1\r\nHost: api.loganalytics.io\r\nConnection: close\r\n\r\n',
       _onPendingData: [Function: noopPendingOutput],
       agent:
        Agent {
          _events: [Object],
          _eventsCount: 1,
          _maxListeners: undefined,
          defaultPort: 443,
          protocol: 'https:',
          options: [Object],
          requests: {},
          sockets: [Object],
          freeSockets: {},
          keepAliveMsecs: 1000,
          keepAlive: false,
          maxSockets: Infinity,
          maxFreeSockets: 256,
          maxCachedSessions: 100,
          _sessionCache: [Object] },
       socketPath: undefined,
       timeout: undefined,
       method: 'GET',
       path:
        '/v1/workspaces/MYWORKSPACEGUID/query?query=externalapistatus_CL',
       _ended: true,
       res:
        IncomingMessage {
          _readableState: [ReadableState],
          readable: false,
          _events: [Object],
          _eventsCount: 3,
          _maxListeners: undefined,
          socket: [TLSSocket],
          connection: [TLSSocket],
          httpVersionMajor: 1,
          httpVersionMinor: 1,
          httpVersion: '1.1',
          complete: true,
          headers: [Object],
          rawHeaders: [Array],
          trailers: {},
          rawTrailers: [],
          aborted: false,
          upgrade: false,
          url: '',
          method: null,
          statusCode: 403,
          statusMessage: 'Forbidden',
          client: [TLSSocket],
          _consuming: false,
          _dumped: false,
          req: [Circular],
          responseUrl:
           'https://api.loganalytics.io/v1/workspaces/427fa6ee-41cd-4570-b201-ef6cda4bd314/query?query=externalapistatus_CL',
          redirects: [] },
       aborted: undefined,
       timeoutCb: null,
       upgradeOrConnect: false,
       parser: null,
       maxHeadersCount: null,
       _redirectable:
        Writable {
          _writableState: [WritableState],
          writable: true,
          _events: [Object],
          _eventsCount: 2,
          _maxListeners: undefined,
          _options: [Object],
          _redirectCount: 0,
          _redirects: [],
          _requestBodyLength: 0,
          _requestBodyBuffers: [],
          _onNativeResponse: [Function],
          _currentRequest: [Circular],
          _currentUrl:
           'https://api.loganalytics.io/v1/workspaces/MyWORKSPACEGUIDhMbhZeHs7D9U0Xi1Dcw6dHbwbfgn-zThudKTXVfxFxv0KakinWdzGXkLlH_BHvAKrYw/query?query=externalapistatus_CL' },
       [Symbol(isCorked)]: false,
       [Symbol(outHeadersKey)]:
        [Object: null prototype] {
          accept: [Array],
          authorization: [Array],
          'content-type': [Array],
          'user-agent': [Array],
          host: [Array] } },
    data:
     { error:
        { message: 'The provided authentication is not valid for this resource',
          code: 'InvalidTokenError',
          innererror: [Object] } } }
  </code></pre>