title: Azure Ad authentication by passing username and password to get the jwt token
body: <p>Currently i am trying to implement the azure active directory authentication by passing user name and password. So for this i have trying to get the access toke but facing issue to get the same. If i use the client id and client secret then i am able to get the token but when i try to by passing username and password then its not giving the result and throwing the exception :
  "error":"invalid_client","error_description":"AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'</p>
  
  <p>Below the code which i am using for this:</p>
  
  <pre><code> /// &lt;summary&gt;
      ///     Working with client id and client secret
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public async Task&lt;string&gt; GetTokenUsingClientSecret()
      {
          //authentication parameters
          string clientID = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
          string clientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXX";
          string directoryName = "xxx.onmicrosoft.com";
          var credential = new ClientCredential(clientID, clientSecret);
  
          var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/" + directoryName, false);
          var result = await authenticationContext.AcquireTokenAsync("https://management.core.windows.net/", clientCredential: credential);
  
          if (result == null)
          {
              throw new InvalidOperationException("Failed to obtain the JWT token");
          }
          string token = result.AccessToken;
          return token;
      }
  
      /// &lt;summary&gt;
      ///     Not Working with username and password.
      /// &lt;/summary&gt;
      public async Task&lt;string&gt; GetTokenUsingUserNamePassword()
      {
          try
          {
              string user = "username.onmicrosoft.com";
              string pass = "yourpassword";
              string directoryName = "XXXX.onmicrosoft.com";
              string authority = "https://login.microsoftonline.com";
              string resource = "https://management.core.windows.net/";
              string clientId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  
              var credentials = new UserPasswordCredential(user, pass);
              var authenticationContext = new AuthenticationContext($"{authority}/{directoryName}");
              var result = authenticationContext.AcquireTokenAsync(resource: resource, clientId: clientId, userCredential: credentials);
  
              return result.Result.AccessToken;
          }
          catch (Exception ex)
          {
  
              throw ex;
          }
      }
  </code></pre>