title: Is there a way to pass JWT Token for Auth into Selenium WebDriver in C# Asp.net Core?
body: <p>I need a way to Authenticate myself on my WebAPI Automation. I have extracted the bearer token and passed my json into a .net object , how do I pass in the JWT / Bearer Token &amp; inject the needed headers into a ChromeDriver Session when it opens so when my app navigates to https://localhost:5000/login it should automatically redirect to -&gt; https://localhost:5000/Dashboard.</p>
  <pre><code>class Program
  {
  
      //private static IWebDriver driver;
  
      // ******-&gt;Selenium Specific Code&lt;-******
      // Instantiate the Chrome Driver
      var driver = new ChromeDriver(&quot;/usr/local/bin/&quot;);
  
      static IJavaScriptExecutor jsDriver = driver as IJavaScriptExecutor;
  
      public static string setItemInLocalStorage(string item, string value)
      {
  
  
          var js = ((IJavaScriptExecutor)driver).ExecuteScript(String.Format(
           &quot;window.localStorage.setItem('userDetails','&quot; + value + &quot;');&quot;));
  
          return &quot;&quot;;
  
      }
  
      //Method to Authenticate &amp; GET Bearer Token from API.
  
      public static async void GetAllWorkshopData(int WorkshopId)
      {
          UserAuth ua = new UserAuth();
          ua.EmailAddress = &quot;example@mail.com&quot;;
          ua.Password = &quot;Strongest!!!Pwd&quot;;
          ua.WorkshopId = WorkshopId;
  
          using (var client = new HttpClient())
          {
  
              var uri = &quot;https://localhost:5001/api/userauth/Login&quot;;
              string json = JsonConvert.SerializeObject(ua);
              StringContent content = new StringContent(json, Encoding.UTF8, &quot;application/json&quot;);
              var res = await client.PostAsync(uri, content);
              string datar = await res.Content.ReadAsStringAsync();
  
              Example details = JsonConvert.DeserializeObject&lt;Example&gt;(datar);
  
  
  
              
              // Navigate to the Endpoint
              ///here inject basic-auth token before selenium opens browser
  
              driver.Navigate().GoToUrl(&quot;http://localhost:5000/Login&quot;);
            
  
              setItemInLocalStorage(&quot;&quot;, datar);
  
              driver.Navigate().GoToUrl(&quot;http://localhost:5000/Dashboard&quot;);
          } 
  </code></pre>