private async Task <IApiClient> GetApiClientInstanceAsync(Config configLocal) { var logger = new NullLogger(); var cryptoProvider = new CryptographyProvider(); IApiClient client = null; if (string.IsNullOrEmpty(configLocal.ConnectionInfo.ApiKey) == false) { Logger.Warn("If api key is granted manually (thru advanced -> security in admin panel), it will only work then in test mode. Use login/password or api key generated in user context to be able to delete items."); client = new ApiClient(logger, configLocal.ConnectionInfo.Endpoint, configLocal.ConnectionInfo.ApiKey, cryptoProvider); } else { var device = new Device { DeviceId = string.Empty, DeviceName = string.Empty }; client = new ApiClient(logger, configLocal.ConnectionInfo.Endpoint, "EmbyFileCleaner", device, Program.GetAssemblyVersion(), cryptoProvider); string passwordMd5 = ConnectService.GetConnectPasswordMd5(configLocal.ConnectionInfo.Password ?? string.Empty, cryptoProvider); var authResult = await client.AuthenticateUserAsync(configLocal.ConnectionInfo.Username, passwordMd5); client = new ApiClient(logger, configLocal.ConnectionInfo.Endpoint, authResult.AccessToken, cryptoProvider); } return(client); }