public async Task <ActionResult> Install() { var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value; var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.Authority); var accessToken = string.Empty; try { var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.EwsResourceId, new ClientCredential(SettingsHelper.ClientId, SettingsHelper.AppKey), new UserIdentifier(userObjectId, UserIdentifierType.UniqueId)); accessToken = authResult.AccessToken; } catch (AdalException ex) { return(RedirectToAction("SignIn", "Account")); } ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); service.HttpHeaders.Add("Authorization", "Bearer " + accessToken); service.TraceEnabled = true; service.TraceFlags = TraceFlags.All; service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx"); try { var apps = service.GetAppManifests(); using (var fs = System.IO.File.OpenRead(Path.Combine(HostingEnvironment.MapPath("~/App_Data"), "OutlookAddinManifest.xml"))) { service.InstallApp(fs); } } catch (Exception e) { var i = e.InnerException as WebException; if (i != null) { var r = new StreamReader(i.Response.GetResponseStream()).ReadToEnd(); } throw; } return(View()); }
private void btnGetAppsManifest_Click(object sender, EventArgs e) { System.Collections.ObjectModel.Collection <System.Xml.XmlDocument> oCollection = _CurrentService.GetAppManifests(); string sInfo = string.Empty; StringBuilder oSB = new StringBuilder(); foreach (System.Xml.XmlDocument xd in oCollection) { oSB.AppendLine("\r\n============================\r\n{0}"); oSB.AppendLine(xd.OuterXml); } textBox1.Text = oSB.ToString(); }