4

UCWA 文档指出,UCWA 当前仅适用于在本地拥有 Lync 的客户。

尽管如此,如果对 Office 365 帐户使用Lync 连接分析器,似乎可以连接到 UCWA 服务:已完成移动性测试 (UCWA) 服务。此外,如果我检查此工具(例如使用 Fiddler)执行的 Web 请求,我可以获取它(以某种方式)从 Office 365 获得的身份验证令牌,并使用它向 UCWA 发出请求。

  • 好像UCWA被Office 365暴露了,是这样吗?Lync 连接分析器似乎使用某个WebTicket 服务来获取身份验证令牌。
  • 是否有任何库可以抽象 WebTicket Service 的使用以获取身份验证令牌?获得令牌后,访问 UCWA 资源将非常简单——不过,一个库也会很好:)
  • 我找不到太多关于 WebTicket 服务 (WCF) 的文档。如果我将服务引用(Visual Studio)添加到https://lyncweb.domain.com/WebTicket/WebTicketService.svc,没有太多选项 - 似乎请求和响应消息没有一定的结构,所以调用这个 WebTicket Service 暴露的IssueToken操作是相当棘手的。

链接:

4

2 回答 2

5

你做了一些调查,根据我的信息,WebTicket 应该是 UCWA 的一个可能的身份验证令牌。

不幸的是,文档仍然正确地说 UCWA 目前仅支持本地安装。对于 Lync Online/Office 365,它尚未启用。

Office 的用户语音上有一个功能请求,您可以投票和关注。如您所见,预计很快会有公告

https://officespdev.uservoice.com/forums/224641-general/suggestions/5857717-ucwa-for-lync-365

于 2014-08-04T08:15:13.603 回答
4

看起来 Office 365 至少公开了 UCWA 功能的一个不错的子集。Lync Connectivity Analyzer 实际上是一个 .NET 应用程序,因此直接利用它来完成繁重的工作并不难。它不如使用“友好”库那么好,但在我的各种原型设计中它对我来说效果很好。使用下面的代码,我可以获取网络票值和 UCWA 基本 URL(通过自动发现),然后去城镇查询 API。这不是最漂亮的代码,但它可以工作。

注意:您需要在 Lync 连接分析器中添加对托管 DLL 的引用。对我来说,这意味着:

  • Credentials.dll
  • LyncConnectivityAnalyzer.Logging.dll
  • LyncConnectivityAnalyzer.Resources.dll
  • LyncWebServices.dll
  • Utilities.dll

您还需要将非托管 DLL(可能只有一个,但我两个都做了)复制到与您的应用程序相同的文件夹(例如\bin\文件夹)。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Security;
using System.Threading.Tasks;
using LyncConnectivityAnalyzer.Logging;
using Microsoft.LyncServer.WebServices;
using Microsoft.Utilities.Credentials;

namespace SM.CoolStuff
{
    /// <summary>
    /// Helper class for performing auto-discovery and authentication to the Lync/Skype UCWA sevice on Office365
    /// </summary>
    public class SkypeHelper
    {
        private string _webTicket;
        private string _ucwaRootPath;
        private readonly ILyncLogging _logger = new Logger();

        /// <summary>
        /// Initializes the connection/authentication/etc.  Once this method completes, <see cref="_webTicket"/> and <see cref="_ucwaRootPath"/> will
        /// be populated.
        /// </summary>
        private async Task Initialize(string userName, SecureString password)
        {
            //Setup the credential
            var userCreds = new Credentials
            {
                UPN = userName,
                SecurePassword = password,
                credsType = CredInputType.CredDialog,
                URI = userName
            };

            //Perform auto-discovery to get the UCWA path
            //We'll just always allow redirects
            ValidateRedirectRequestDelegate alwaysAllowRedirect = (logger, url, destinationUrl) => true;
            var adm = new AutoDiscoverManager(_logger, "http://lyncdiscover." + userCreds.Domain, userCreds.URI, userCreds, alwaysAllowRedirect);
            await adm.StartDiscoveryJourney();

            //Save the path
            _ucwaRootPath = adm.GetAutoDiscoverAddress().ExternalUcwa;

            //Setup the 'validator' that does all the heavy lifting
            var webServicesValidation = new WebServicesValidation(_logger, _ucwaRootPath, userCreds)
            {
                HttpRequestBody = ApplicationPostBody,
                customHeaders = CustomHeaders,
                getPost = HttpMethod.Post
            };

            //Make a first request that should gracefully fail with 'authorization required'
            await webServicesValidation.CheckURL(_ucwaRootPath, false);

            //Now authorize the request
            await webServicesValidation.TryURLAuth(_ucwaRootPath);

            //Use some ugly reflection to get the ticket value.  There may be a better way but this works
            _webTicket = (string)WebTicketField.GetValue(webServicesValidation);
        }

        /// <summary>
        /// Example usage
        /// </summary>
        public async Task DoSomethingOnSkype()
        {
            //If you already have a SecureString, might as well use that.  Otherwise, convert an 'insecure' string to be 'Secure'
            var secureString = new SecureString();
            "TopSecret".ToList().ForEach(secureString.AppendChar);

            //Do the initialization
            await Initialize("user@somewhere.com", secureString);

            //TODO: Use _webTicket and _host to query something
        }

        private static readonly string ApplicationPostBody =
            string.Concat(
                "<input xmlns=\"http://schemas.microsoft.com/rtc/2012/03/ucwa\"><property name=\"culture\">en-US</property><property name=\"endpointId\">44:D8:84:3C:68:68</property><property name=\"type\">Phone</property><property name=\"userAgent\">",
                //TODO: Your app name here
                "LyncConnectivityAnalyzer", "/",
                //TODO: Your app version here
                "5.0.8308.582",
                " (Windows OS 6.0)</property></input>");

        private static readonly Dictionary<string, string> CustomHeaders = new Dictionary<string, string>
        {
            {"Accept", "application/vnd.microsoft.com.ucwa+xml"},
            {"Content-Type", "application/vnd.microsoft.com.ucwa+xml"},
            {"X-MS-Namespace", "internal"},
            {"Connection", "keep-alive"},
            {"Proxy-Connection", "keep-alive"}
        };

        private static readonly FieldInfo WebTicketField = FindWebTicketField();

        private static FieldInfo FindWebTicketField()
        {
            var fieldInfo = typeof(WebServicesValidation).GetField("_webticket", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fieldInfo == null)
            {
                throw new ApplicationException("Could not find private _webticket field");
            }
            return fieldInfo;
        }
   }
}
于 2015-07-30T01:23:24.733 回答