private void TimerRunSync(Object state) { List <DBUser> users = DatabaseHandler.GetSyncs(); if (!ADHandler.ReloadGroup()) { Logger.Send("Target group could not be reloaded during sync check. was the group deleted?", Logger.LogLevel.ERROR, 17); } O365Client client = new O365Client(); try { client.GetAccessToken(ConfigHandler.O365TenantName, ConfigHandler.ClientID, ConfigHandler.ClientSecret, ConfigHandler.O365ServiceUsername, ConfigHandler.O365ServicePassword).Wait(); } catch (AggregateException ae) { foreach (Exception e in ae.Flatten().InnerExceptions) { Logger.Send("Exception thrown when requesting an Access Token from O365: " + e.Message, Logger.LogLevel.ERROR, 17); } } catch (Exception ex) { Logger.Send("Exception thrown when requesting an Access Token from O365: " + ex.Message, Logger.LogLevel.ERROR, 17); } foreach (DBUser user in users) { Logger.Send("Syncing password for user: "******" originally changed at " + user.TimestampDatetime.ToLocalTime().ToString(), Logger.LogLevel.INFO, 17); try { client.ChangePassword(user.Username, user.Password).Wait(); user.Processed = SyncProcessedStatus.COMPLETE; } catch (AggregateException ae) { foreach (Exception e in ae.Flatten().InnerExceptions) { Logger.Send("Exception thrown when changing users password: "******"Exception thrown when changing users password: " + ex.Message, Logger.LogLevel.ERROR, 17); user.Processed = SyncProcessedStatus.FAILED; } } DatabaseHandler.UpdateSyncStatus(users); _timerSync.Change(SYNC_WAIT_TIME, Timeout.Infinite); }
static async Task MainAsync() { O365Client client = new O365Client(); try { await client.GetAccessToken("TenantName", ClientID, ClientSecret, userName, userPassword); await client.ChangePassword("testUser", "TestPassword4423"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine(); }