title: Sending a bearer token to endpoint, then validate this token
body: <p>If I have a method that sends some data to an endpoint, I understand I should use a bearer token to authenticate this call, sent in the header of the request.</p>
  
  <p>Say my method that sends/receives data to/from the endpoint looks like this:</p>
  
  <pre><code>public async Task&lt;string&gt; PostGetAsync()
          {
              var uri = new Uri("https://localhost:44322/endpoint");
  
              using (var client = new HttpClient())
              {
                  var pairs = new List&lt;KeyValuePair&lt;string, string&gt;&gt;
                  {
                      new KeyValuePair&lt;string, string&gt;("Key", "Value")
                  };
  
                  var content = new FormUrlEncodedContent(pairs);
                  var response = await client.PostAsync(uri, content);
  
                  if (response.StatusCode != HttpStatusCode.OK)
                  {
                      return "Error posting KeyValue";
                  }
  
                  string responseString = response.Content.ReadAsStringAsync().Result;
  
                  JArray json = JArray.Parse(responseString);
  
                  try
                  {
                      var returnedJson = json[returnedData];
                      return returnedJson.ToString();
                  }
                  catch (Exception e)
                  {
                      return "Index is out of bounds";
                  }
              }
          }
  </code></pre>
  
  <p>And the method that runs when that endpoint is called it this:</p>
  
  <pre><code>public async Task&lt;JsonResult&gt; endpoint()
          {
              List&lt;Example&gt; items = new List&lt;Example&gt;();
  
              NameValueCollection nvc = Request.Form;
              string keyString = nvc["Key"];
  
              try
              {
                  items = await GetService.GetList(keyString);
              }
              catch (ServiceException se)
              {
  
              }
  
              return Json(items, JsonRequestBehavior.AllowGet);
          }
  </code></pre>
  
  <p>How do I:</p>
  
  <ul>
  <li>Send a bearer token (custom stored in azure keyvault) to the endpoint.</li>
  <li>Validate this token from the endpoint</li>
  </ul>
  
  <p>I can't find any beginner friendly docs for doing this. </p>