title: How to create SAS token for Azure Data Lake Store (Gen-2) using service principals (clientId and clientSecret) in C#?
body: <p>I have the clientId and clientSecret of Data Lake Store (Gen-2) and I am looking for a way to create SAS token for it in a programmatic way using C#. I have gone through the documentation but have not find a way to create a SAS token. Any guidance will be appreciated. Thanks.</p>
  
  <p>As suggested by Md Farid Uddin Kiron, I used this code but unsuccessful:</p>
  
  <pre><code>//Token Request End Point
  string tokenUrl = $"https://login.microsoftonline.com/&lt;tenantId&gt;.onmicrosoft.com/oauth2/token";
  var tokenRequest = new HttpRequestMessage(HttpMethod.Post, tokenUrl);
  
  //I am Using client_credentials as It is mostly recommended
  tokenRequest.Content = new FormUrlEncodedContent(new Dictionary&lt;string, string&gt;
              {
                  ["grant_type"] = "client_credentials",
                  ["client_id"] = "--------",
                  ["client_secret"] = "-------",
                  ["resource"] = "https://&lt;datalake gen2 name&gt;.dfs.core.windows.net/"
              });
  
              dynamic json;
  AccessTokenClass results = new AccessTokenClass();
  HttpClient client = new HttpClient();
  
  var tokenResponse = client.SendAsync(tokenRequest).GetAwaiter();
  
  json = tokenResponse.GetResult().Content.ReadAsStringAsync().GetAwaiter();
  results = JsonConvert.DeserializeObject&lt;AccessTokenClass&gt;(json);
  </code></pre>
  
  <p>It is giving me status 400 error.</p>