title: Microsoft Graph API Scripted Authentication
body: <p>How does one authenticate as a user without any direct user interaction?</p>
  <hr />
  <p>Otherwise i found a workaround with client credential flow in this example : <a href="https://github.com/microsoftgraph/console-csharp-snippets-sample" rel="nofollow noreferrer">https://github.com/microsoftgraph/console-csharp-snippets-sample</a>
  but if i try to implement this code in an c# Asp.net mav applcition or a windows forms application i cant get an application token. If i debug the app it stuck at waiting for token but it doesn't throw an error (virus protection already deactivated). Does anyone have a idea for the main problem or my workaround?</p>
  <p>This is the Code for my workaround trying to get a token, but stuck on daemonClient.AcquireTokenForClientAsync.</p>
  <pre><code>   public async Task&lt;Users&gt; GetUser(string Username)
      {
          MSALCache appTokenCache = new MSALCache(clientId);
  
          ClientCredential clientdummy = new ClientCredential(clientSecret);
          
          ConfidentialClientApplication daemonClient = new ConfidentialClientApplication(clientId, string.Format(AuthorityFormat, tenantId), redirectUri,
                                                              clientdummy, null, null);
  
          authenticate(daemonClient).Wait();
  
          string token = authResult.AccessToken;
  
          client = GetAuthenticatedClientForApp(token);
  
          IGraphServiceUsersCollectionPage users = client.Users.Request().GetAsync().Result;
      }
  
      private async Task&lt;AuthenticationResult&gt; authenticate(ConfidentialClientApplication daemonClient)
      {
          authResult = await daemonClient.AcquireTokenForClientAsync(new[] { MSGraphScope });
          return authResult;
      }
  </code></pre>