title: Invalid Client Authorization header when trying to get token from "Here" REST API
body: <p>I am trying to get a Bearer token to start using <strong>HERE REST API</strong>,<br/>
   using (OAuth 2.0 (JSON Web Tokens))<br/>
   after a lot of struggles, I am stuck with <a href="https://developer.here.com/olp/documentation/access_control/dev_guide/topics/error-messages.html" rel="nofollow noreferrer">401202 error</a>:</p>
  
  <blockquote>
    <p>{"errorId":"ERROR-e0242f30-05da-4df0-9beb-b697062240ce","httpStatus":401,"errorCode":401202,"message":"Invalid
    Client Authorization header, expecting signed request
    format.","error":"invalid_request","error_description":"errorCode:
    '401202'. Invalid Client Authorization header, expecting signed
    request format."}</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>private void GetToken()
  {
     try
      {
          var here_client_id = "b1Ibl7XXXXXXXoZtNKb";
          var here_access_key_id = "8DKjlwXXXXXXXXXerGCXPA";
          var here_access_key_secret = "tuU-bGMa1ljancfoXXXXXXXXXXXXXXXK8cMlk4o0EGUpS2fmwkAtlltFPDhYQUgytJLL-X_YNIjmdWcOabQ";
          var url = "https://account.api.here.com/oauth2/token";
  
          var Parameters = "grant_type=client_credentials&amp;client_id=" + here_client_id + "&amp;oauth_consumer_key=" + here_access_key_secret;
  
          var hmac = new HMACSHA256();
          var key = Convert.ToBase64String(hmac.Key);
          Guid id = Guid.NewGuid();
  
          // Create a request for the URL.        
          WebRequest request = WebRequest.Create(url);
  
          request.Method = "POST";
          request.ContentType = "application/x-www-form-urlencoded";
          var cred = @"OAuth oauth_consumer_key=" + here_access_key_id;
  
          request.Headers.Add("Authorization", cred);
          //request.Headers.Add("oauth_consumer_key", here_access_key_id);
          request.Headers.Add("oauth_nonce", id.ToString());
          request.Headers.Add("oauth_signature_method", "HMAC-SHA256");
          request.Headers.Add("oauth_signature", key);
          request.Headers.Add("oauth_timestamp", ConvertToUnixTimestamp(DateTime.Now).ToString());
          request.Headers.Add("oauth_version", "1.0");
  
          byte[] byteArray = Encoding.UTF8.GetBytes(Parameters);
          request.ContentLength = byteArray.Length;
  
          Stream postStream = request.GetRequestStream();
          // Add the post data to the web request
          postStream.Write(byteArray, 0, byteArray.Length);
          postStream.Close();
  
          // Get the response.
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
          // Display the status.
          Console.WriteLine(response.StatusDescription);
          // Get the stream containing content returned by the server.
          Stream dataStream = response.GetResponseStream();
          // Open the stream using a StreamReader for easy access.
          StreamReader reader = new StreamReader(dataStream);
          // Read the content.
          string responseFromServer = reader.ReadToEnd();
          // Display the content.
          MessageBox.Show(responseFromServer);
          // Cleanup the streams and the response.
          reader.Close();
          dataStream.Close();
          response.Close();
      }
      catch (WebException ex)
      {
          using (var stream = ex.Response.GetResponseStream())
          using (var reader = new StreamReader(stream))
          {
             //MessageBox.Show(reader.ReadToEnd());
              textBox1.Text = reader.ReadToEnd();
          }
      }
  }
  </code></pre>