internal static string GetUcwaDiscoveryUrl(string userAddress, ICredentials credentials)
        {
            int num = userAddress.LastIndexOf("@");

            if (num <= 0)
            {
                return(string.Empty);
            }
            string domain = userAddress.Substring(num + 1);
            LyncAnonymousAutodiscoverResult authenticatedAutodiscoverEndpoint = LyncAutodiscoverWorker.GetAuthenticatedAutodiscoverEndpoint(userAddress, domain);
            string authenticatedServerUri = authenticatedAutodiscoverEndpoint.AuthenticatedServerUri;

            if (string.IsNullOrEmpty(authenticatedServerUri.Trim()) || authenticatedServerUri.Length == 0)
            {
                return(string.Empty);
            }
            LyncAutodiscoverResult ucwaUrl = LyncAutodiscoverWorker.GetUcwaUrl(authenticatedAutodiscoverEndpoint.AuthenticatedServerUri, credentials);

            return(ucwaUrl.UcwaDiscoveryUrl);
        }
Пример #2
0
        public static ResultType SendLyncOAuthRequest(ADUser user, Uri targetUri, out string diagnosticMessage, bool appOnly = false, bool useCachedToken = false, bool reloadConfig = false)
        {
            int              startIndex       = user.GetFederatedIdentity().Identity.IndexOf('@') + 1;
            string           domain           = user.GetFederatedIdentity().Identity.Substring(startIndex);
            StringBuilder    stringBuilder    = new StringBuilder();
            ICredentials     icredentials     = TestOAuthConnectivityHelper.GetICredentials(appOnly, user, domain);
            OAuthCredentials oauthCredentials = icredentials as OAuthCredentials;
            string           text             = string.Empty;

            foreach (ProxyAddress proxyAddress in user.EmailAddresses)
            {
                if (proxyAddress.ToString().Contains("sip:"))
                {
                    text = TestOAuthConnectivityHelper.FromSipFormat(proxyAddress.ToString());
                }
            }
            if (string.IsNullOrEmpty(text))
            {
                text = user.PrimarySmtpAddress.ToString();
            }
            if (string.IsNullOrEmpty(text))
            {
                diagnosticMessage = Strings.EMailAddressNotFound(user.Alias);
                return(ResultType.Error);
            }
            Guid value = Guid.NewGuid();

            oauthCredentials.ClientRequestId = new Guid?(value);
            stringBuilder.AppendLine(Strings.ClientRequestId(value.ToString()));
            string value2 = TestOAuthConnectivityHelper.CheckReloadConfig(reloadConfig);
            string value3 = TestOAuthConnectivityHelper.CheckUseCachedToken(useCachedToken);

            stringBuilder.AppendLine(value2);
            stringBuilder.AppendLine(value3);
            ValidationResultCollector resultCollector    = new ValidationResultCollector();
            LocalConfiguration        localConfiguration = LocalConfiguration.Load(resultCollector);

            oauthCredentials.Tracer             = new TestOAuthConnectivityHelper.TaskOauthOutboundTracer();
            oauthCredentials.LocalConfiguration = localConfiguration;
            LyncAnonymousAutodiscoverResult lyncAnonymousAutodiscoverResult = null;

            try
            {
                lyncAnonymousAutodiscoverResult = LyncAutodiscoverWorker.GetAuthenticatedAutodiscoverEndpoint(text, domain);
            }
            catch (WebException ex)
            {
                stringBuilder.AppendLine(Strings.DiagnosticsHeader);
                stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
                stringBuilder.AppendLine(Strings.AutodiscoverFailure);
                stringBuilder.AppendLine(Strings.TestOutboundOauthLog);
                stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
                stringBuilder.AppendLine(ex.ToString());
                diagnosticMessage = stringBuilder.ToString();
                return(ResultType.Error);
            }
            catch (Exception ex2)
            {
                stringBuilder.AppendLine(Strings.DiagnosticsHeader);
                stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
                stringBuilder.AppendLine(Strings.AutodiscoverFailure);
                stringBuilder.AppendLine(Strings.TestOutboundOauthLog);
                stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
                stringBuilder.AppendLine(ex2.ToString());
                diagnosticMessage = stringBuilder.ToString();
                return(ResultType.Error);
            }
            if (string.IsNullOrEmpty(lyncAnonymousAutodiscoverResult.AuthenticatedServerUri))
            {
                stringBuilder.AppendLine(Strings.DiagnosticsHeader);
                stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
                stringBuilder.AppendLine(Strings.TestOutboundOauthLog);
                stringBuilder.AppendLine(Strings.NoAuthenticatedServerUri);
                stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
                diagnosticMessage = stringBuilder.ToString();
                return(ResultType.Error);
            }
            stringBuilder.AppendLine(Strings.DiagnosticsHeader);
            stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
            LyncAutodiscoverResult lyncAutodiscoverResult = null;

            try
            {
                lyncAutodiscoverResult = LyncAutodiscoverWorker.GetUcwaUrl(lyncAnonymousAutodiscoverResult.AuthenticatedServerUri, icredentials);
            }
            catch (WebException ex3)
            {
                stringBuilder.AppendLine(Strings.DiagnosticsHeader);
                stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
                stringBuilder.AppendLine(Strings.UCWADiscoveryUrlException);
                stringBuilder.AppendLine(lyncAutodiscoverResult.Response);
                stringBuilder.AppendLine(Strings.TestOutboundOauthLog);
                stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
                stringBuilder.AppendLine(ex3.ToString());
                diagnosticMessage = stringBuilder.ToString();
                return(ResultType.Error);
            }
            catch (Exception ex4)
            {
                stringBuilder.AppendLine(Strings.DiagnosticsHeader);
                stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
                stringBuilder.AppendLine(Strings.UCWADiscoveryUrlException);
                stringBuilder.AppendLine(lyncAutodiscoverResult.Response);
                stringBuilder.AppendLine(Strings.TestOutboundOauthLog);
                stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
                stringBuilder.AppendLine(ex4.ToString());
                diagnosticMessage = stringBuilder.ToString();
                return(ResultType.Error);
            }
            if (string.IsNullOrEmpty(lyncAutodiscoverResult.UcwaDiscoveryUrl))
            {
                stringBuilder.AppendLine(Strings.DiagnosticsHeader);
                stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
                stringBuilder.AppendLine(Strings.TestOutboundOauthLog);
                stringBuilder.AppendLine(Strings.UCWADiscoveryUrlEmpty);
                stringBuilder.AppendLine(lyncAutodiscoverResult.Response);
                stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
                diagnosticMessage = stringBuilder.ToString();
                return(ResultType.Error);
            }
            stringBuilder.AppendLine(Strings.DiagnosticsHeader);
            stringBuilder.AppendLine(lyncAnonymousAutodiscoverResult.DiagnosticInfo);
            stringBuilder.AppendLine(Strings.TestOutboundOauthLog);
            stringBuilder.AppendLine(oauthCredentials.Tracer.ToString());
            diagnosticMessage = stringBuilder.ToString();
            return(ResultType.Success);
        }