private async System.Threading.Tasks.Task AcquireAccessTokenAsync(string ClientId) { Cursor = Cursors.WaitCursor; Enabled = false; string[] scopes = Util.MailboxViewerScopes(); _pca = new PublicClientApplication(ClientId); StringBuilder stringBuilder = new StringBuilder(); try { stringBuilder.AppendLine("MSAL - AcquireTokenAsync"); stringBuilder.AppendLine("Application ID : " + ClientId); stringBuilder.AppendLine("Scope : " + string.Join(",", scopes)); _ar = await _pca.AcquireTokenAsync(scopes, "", UIBehavior.ForceLogin, ""); stringBuilder.AppendLine("Result : Success"); stringBuilder.AppendLine("AccessToken : " + (_ar.AccessToken ?? "")); stringBuilder.AppendLine("ExpiresOn : " + _ar.ExpiresOn.ToString()); stringBuilder.AppendLine("IdToken : " + (_ar.IdToken ?? "")); stringBuilder.AppendLine("Scope : " + string.Join(",", _ar.Scopes)); stringBuilder.AppendLine("UniqueId : " + (_ar.UniqueId ?? "")); stringBuilder.AppendLine("DisplayableId : " + (_ar.User.DisplayableId ?? "")); stringBuilder.AppendLine("Identifier : " + (_ar.User.Identifier ?? "")); stringBuilder.AppendLine("Name : " + (_ar.User.Name ?? "")); Properties.Settings.Default.Save(); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { stringBuilder.AppendLine("Result : Fail"); stringBuilder.AppendLine("Message : " + ex.Message); if (ex.Message != "User canceled authentication") { MessageBox.Show(ex.Message, "Office365APIEditor"); } } finally { Cursor = Cursors.Default; Enabled = true; } Util.WriteCustomLog("AcquireViewerTokenForm", stringBuilder.ToString()); }