internal static WacResult ExecuteWacRequest(string wacTemplateUrl, string owaTemplateUrl, ADUser user, StringBuilder diagnosticsDetails) { string text = string.Empty; string text2 = string.Empty; string text3 = string.Empty; WacRequestState wacRequestState = new WacRequestState(); WacResult wacResult = new WacResult(); try { string text4 = user.PrimarySmtpAddress.ToString(); if (string.IsNullOrEmpty(text4)) { diagnosticsDetails.AppendLine(string.Format("Primary SMTP Address not found for user {0}", user.Alias)); wacResult.Error = wacRequestState.Error; return(wacResult); } text = WacWorker.GenerateWopiSrcUrl(owaTemplateUrl, text4); LocalTokenIssuer localTokenIssuer = new LocalTokenIssuer(user.OrganizationId); TokenResult wacCallbackToken = localTokenIssuer.GetWacCallbackToken(new Uri(text, UriKind.Absolute), text4, Guid.NewGuid().ToString()); text3 = wacCallbackToken.TokenString; text2 = WacWorker.GenerateWacIFrameUrl(text, wacTemplateUrl, text4, text3); text = string.Format("{0}&access_token={1}", text, text3); diagnosticsDetails.AppendLine("Probe Details:"); diagnosticsDetails.AppendLine("WacIFrameUrl:"); diagnosticsDetails.AppendLine(text2); diagnosticsDetails.AppendLine("ExchangeCheckFileUrl:"); diagnosticsDetails.AppendLine(text); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(text2); wacRequestState.Request = httpWebRequest; wacRequestState.WacIFrameUrl = text2; wacRequestState.WopiUrl = text; wacRequestState.Error = false; wacRequestState.DiagnosticsDetails = diagnosticsDetails; WacWorker.allDone.Reset(); WacWorker.latencyMeasurementStart = DateTime.UtcNow; IAsyncResult asyncResult = httpWebRequest.BeginGetResponse(new AsyncCallback(WacWorker.ProcessWacResponse), wacRequestState); ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(WacWorker.TimeoutCallback), httpWebRequest, 120000, true); WacWorker.allDone.WaitOne(); if (wacRequestState.Response != null) { wacRequestState.Response.Close(); } } catch (WebException ex) { diagnosticsDetails.AppendLine("Stack Trace:"); diagnosticsDetails.AppendLine(string.Format("Exception: {0}.", ex.ToString())); for (Exception innerException = ex.InnerException; innerException != null; innerException = innerException.InnerException) { diagnosticsDetails.AppendLine(string.Format("Inner Exception: {0}.", innerException.ToString())); } diagnosticsDetails.AppendLine("Diagnostic Tip: There is an unhandled exception occured while running Wac Probe. Please look into the exception details."); wacRequestState.Error = true; } wacResult.Error = wacRequestState.Error; return(wacResult); }
// Token: 0x06001AD9 RID: 6873 RVA: 0x0006615C File Offset: 0x0006435C private static TokenResult GetOAuthToken(string ewsAttachmentId, UserContext userContext, string mailboxSmtpAddress, string wopiSrcUrl) { LocalTokenIssuer localTokenIssuer = new LocalTokenIssuer(userContext.ExchangePrincipal.MailboxInfo.OrganizationId); TokenResult wacCallbackToken = localTokenIssuer.GetWacCallbackToken(new Uri(wopiSrcUrl, UriKind.Absolute), mailboxSmtpAddress, ewsAttachmentId); if (wacCallbackToken == null) { throw new InvalidOperationException("OAuth TokenResult is null."); } return(wacCallbackToken); }
private static string GetACSToken(OrganizationId tenantID, IConfigurationSession dataSession, ExecutionLog logger, Task task) { string result = null; LocalTokenIssuer localTokenIssuer = new LocalTokenIssuer(tenantID); LocalConfiguration configuration = ConfigProvider.Instance.Configuration; Uri uri = null; string text = null; string applicationId = configuration.ApplicationId; string text2 = null; foreach (PartnerApplication partnerApplication in configuration.PartnerApplications) { if (partnerApplication.Enabled && partnerApplication.Name.Contains("Intune")) { text2 = partnerApplication.ApplicationIdentifier; break; } } foreach (AuthServer authServer in configuration.AuthServers) { if (authServer.Enabled && authServer.Type == AuthServerType.MicrosoftACS) { text = authServer.IssuerIdentifier; uri = new Uri(authServer.TokenIssuingEndpoint); break; } } if (localTokenIssuer.SigningCert == null) { logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Error, "No certificate found.", null); } if (text2 == null) { logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Error, "No partnerId found.", null); } if (uri == null) { logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Error, "No authorizationEndpoint found.", null); } if (string.IsNullOrEmpty(text)) { logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Error, "No issuerIdentifier found.", null); } if (localTokenIssuer.SigningCert != null && text2 != null && uri != null && !string.IsNullOrEmpty(text)) { string arg = applicationId; string arg2 = text2; string intuneResourceUrl = UnifiedPolicyConfiguration.GetInstance().GetIntuneResourceUrl(dataSession); string arg3 = text; string authority = uri.Authority; string text3 = string.Format("{0}@{1}", arg, tenantID.ToExternalDirectoryOrganizationId()); string text4 = string.Format("{0}/{1}@{2}", arg3, authority, tenantID.ToExternalDirectoryOrganizationId()); string text5 = string.Format("{0}/{1}@{2}", arg2, intuneResourceUrl, tenantID.ToExternalDirectoryOrganizationId()); X509SigningCredentials x509SigningCredentials = new X509SigningCredentials(localTokenIssuer.SigningCert, "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", "http://www.w3.org/2001/04/xmlenc#sha256"); JsonWebSecurityToken jsonWebSecurityToken = new JsonWebSecurityToken(text3, text4, DateTime.UtcNow, DateTime.UtcNow.AddMinutes(5.0), new List <JsonWebTokenClaim>(), x509SigningCredentials); OAuth2AccessTokenRequest oauth2AccessTokenRequest = OAuth2MessageFactory.CreateAccessTokenRequestWithAssertion(jsonWebSecurityToken, text5); OAuth2S2SClient oauth2S2SClient = new OAuth2S2SClient(); try { OAuth2AccessTokenResponse oauth2AccessTokenResponse = (OAuth2AccessTokenResponse)oauth2S2SClient.Issue(uri.AbsoluteUri, oauth2AccessTokenRequest); if (oauth2AccessTokenResponse != null) { result = "Bearer " + oauth2AccessTokenResponse.AccessToken; } } catch (RequestFailedException ex) { ex.ToString(); WebException ex2 = (WebException)ex.InnerException; HttpWebResponse httpWebResponse = (HttpWebResponse)ex2.Response; Stream responseStream = httpWebResponse.GetResponseStream(); Encoding encoding = Encoding.GetEncoding("utf-8"); string text6 = "Auth service call failed: "; if (responseStream != null) { StreamReader streamReader = new StreamReader(responseStream, encoding); char[] array = new char[256]; for (int k = streamReader.Read(array, 0, 256); k > 0; k = streamReader.Read(array, 0, 256)) { text6 += new string(array, 0, k); } } logger.LogOneEntry(task.GetType().Name, string.Empty, ExecutionLog.EventType.Error, text6, ex); } } return(result); }