title: Validation of an Azure AD Bearer Token in a Console Application
body: <p>You can find tons of examples how to secure an ASP.Net Application with Azure AD using JWT Bearer Authentication. It is as easy as adding some Information about your AAD in your Startup, like:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  {
      app.UseJwtBearerAuthentication(new JwtBearerOptions
      {
          Authority = "https://login.windows.net/...",
          Audience = "...",
      });
  
      app.UseMvc();
  }
  </code></pre>
  
  <p>Nothing is wrong with those examples, all the Token-Validation-Magic happens behind the scenes and you don't have to take care about it. But actually I would like to know how to validate an Azure AD Bearer Token apart from ASP.Net, e.g. in a Console Application.</p>
  
  <p>Within a Console Application, I would expect something like the following:</p>
  
  <pre><code>public static void Main(string[] args)
  {
     string token = "...";
  
     JwtSecurityToken validatedJwtToken = validateJwtToken(token);
  }
  
  private static JwtSecurityToken validateJwtToken(string token)
  {
      JwtSecurityToken jwtToken = new JwtSecurityToken(token)
  
      //
      // how to validate the AAD token?!
      //
  
      if(/* is valid */)
      {
          return jwtToken;
      }
      else
      {
          return null;
      }
  }
  </code></pre>
  
  <p>Unfortunately I did't found a working example yet, but I can't imagine there is no easy solution for this problem. Any advice is highly appreciated!</p>