# Log on a desktop application

The following C# code is an example showing how the access token for ELO Sync can be identified for a .NET Core desktop application:

static async Task<string> SignInUserAndGetTokenUsingMSAL(string[] scopes)
{
   string authority = $"<instance>/<tenant-id>"; // e.g. https://login.microsoftonline.com/<tenant-id>
   // Initialization of the MSAL library
   IPublicClientApplication application = PublicClientApplicationBuilder.Create("<own-client-id>")
                                             .WithAuthority(authority)
                                             .WithDefaultRedirectUri()
                                             .Build();
   AuthenticationResult result;
   try
   {
      // If authentication has already been performed, the session will be reused.
      var accounts = await application.GetAccountsAsync();
      result = await application.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
         .ExecuteAsync();
   }
   catch (MsalUiRequiredException ex)
   {
      // If no authentication has been performed yet, a browser window will open where the login details can be entered. After successful authentication, the result is returned with the access token.
      result = await application.AcquireTokenInteractive(scopes)
         .WithClaims(ex.Claims)
         .ExecuteAsync();
   }
   return result.AccessToken;
}
string[] scopes = new string[] { "<elosync-client-id>/.default" };
string bearerToken = await SignInUserAndGetTokenUsingMSAL(scopes);

After this, authentication returns an access token for the application that has to be used for every request to ELO Sync (sent in the HTTP header Authorization as Bearer).

For more information, see Microsoft identity platform code samples for authentication and authorization (opens new window)

Last updated: July 25, 2025 at 7:16 AM