title: Create Microsoft Graph GraphServiceClient with user/password unattended
body: <p>I am creating a console application that connects to Microsoft Graph using the Microsoft Graph API (as shown in <a href="https://github.com/microsoftgraph/console-csharp-connect-sample" rel="noreferrer">https://github.com/microsoftgraph/console-csharp-connect-sample</a>).
  Everything is working fine, but I wonder if there is a way where I can authenticate a user (when I already know their user/password) without them needing to manually enter their credentials on the "Sing in to your account" window rendered on the desktop.
  The idea is basically  to run the application unattended, so there is no need for the user to be entering their credentials when the application starts. I can´t find any relevant information on the subject.
  Is that even possible?</p>
  
  <p>EDIT</p>
  
  <p>After following the link @DanSilver posted about geting access without a user, I tried the sample suggested in that link (<a href="https://github.com/Azure-Samples/active-directory-dotnet-daemon-v2" rel="noreferrer">https://github.com/Azure-Samples/active-directory-dotnet-daemon-v2</a>). Although that is an MVC application that forces users to authenticate (precisely what I wanted to avoid) I have managed to use part of the authentication code in that sample with my console application. After giving authorization to the application manually through a request to  <a href="https://login.microsoftonline.com/myTenantId/adminconsent" rel="noreferrer">https://login.microsoftonline.com/myTenantId/adminconsent</a> I can create a GraphServiceClient in my console app that connects to Graph without user interaction. So I mark the answer as valid.
  Just in case someone is in the same situation, the GraphServiceclient is created as:</p>
  
  <pre><code>GraphServiceClient graphServiceClientApplication = new GraphServiceClient("https://graph.microsoft.com/v1.0", new DelegateAuthenticationProvider(
      async (requestMessage) =&gt;
      {
          string clientId = "yourClientApplicationId";
          string authorityFormat = "https://login.microsoftonline.com/{0}/v2.0";
          string tenantId = "yourTenantId";
          string msGraphScope = "https://graph.microsoft.com/.default";
          string redirectUri = "msalXXXXXX://auth"; // Custom Redirect URI asigned in the Application Registration Portal in the native Application Platform
          string clientSecret = "passwordGenerated"; 
          ConfidentialClientApplication daemonClient = new ConfidentialClientApplication(clientId, String.Format(authorityFormat, tenantId), redirectUri, new ClientCredential(clientSecret), null, new TokenCache());
          AuthenticationResult authResult = await daemonClient.AcquireTokenForClientAsync(new string[] { msGraphScope });
          string token = authResult.AccessToken;
          requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);                            
      }                
  ));
  </code></pre>