title: Attribute To Secure Web Api
body: <p>I am working with a web api where it should have a request key and depending upon it, the api controller will do
  specific task. I am using rest client program in vs code and did the following for testing:</p>
  <pre><code>GET http://localhost:PortNo/WeatherForecast/GetAllTeams
  test: &quot;12345678910&quot; //Key
  </code></pre>
  <p>So in the controller, I did this to get the key value:</p>
  <pre><code>[HttpGet]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;TeamDetails&gt;&gt;&gt; GetAllTeams()
  {
      string Token = Request.Headers[&quot;test&quot;]; //Getting the key value here
      var teams = _service.GetAllTeams();
  
      return Ok(teams)
  }
  </code></pre>
  <p>But I've few things in mind and doing R &amp; D like how can I make the above with an attribute. Say each controller
  will have an attribute as follows and make the request invalid if no proper key found:</p>
  <pre><code>[InvalidToken] //This is the attribute
  [HttpGet]
  public async Task&lt;ActionResult&lt;IEnumerable&lt;TeamDetails&gt;&gt;&gt; GetAllTeams()
  {
     var teams = _service.GetAllTeams();
  
     return Ok(teams)
  }
  </code></pre>
  <p>I am not sure if this is going to make the api secure and my plan is to valid every http request (In my case, a simple form submission at the moment), so it should say the request is generated from the web api app.</p>
  <p><strong>N.B</strong>: I worked with web api earlier in small sections but now a broader thing to implement, so expecting few suggestions that can help me to guide for better design.</p>