如何访问 Lync Online (Office 365) 的 UCWA 终结点?
Posted
技术标签:
【中文标题】如何访问 Lync Online (Office 365) 的 UCWA 终结点?【英文标题】:How to access the UCWA endpoint for Lync Online (Office 365)? 【发布时间】:2014-08-02 08:54:36 【问题描述】:UCWA 文档指出,UCWA 目前仅适用于在本地拥有 Lync 的客户。
不过,如果对 Office 365 帐户使用 Lync Connectivity Analyzer,似乎可以连接到 UCWA 服务:已完成移动 (UCWA) 服务测试。此外,如果我检查此工具(例如使用 Fiddler)执行的 Web 请求,我可以获取它(以某种方式)从 Office 365 获得的身份验证令牌,并使用它向 UCWA 发出请求。
好像UCWA被Office 365暴露了,是这样吗? Lync Connectivity Analyzer 似乎使用了某个 WebTicket Service 来获取身份验证令牌。 是否有任何库可以抽象 WebTicket Service 的使用以获取身份验证令牌?获得令牌后,访问 UCWA 资源将非常简单 - 不过,为此提供一个库也不错:) 我找不到太多关于 WebTicket 服务 (WCF) 的文档。如果我在https://lyncweb.domain.com/WebTicket/WebTicketService.svc 中添加服务引用(Visual Studio),则没有太多选项——请求和响应消息似乎没有特定的结构,因此调用 IssueToken 非常棘手 此 WebTicket 服务公开的操作。链接:
About UCWA Lync Connectivity Analyzer LyncDiscover and Auto Discovery Deeper Dive【问题讨论】:
【参考方案1】:你做了相当多的调查,根据我的信息,WebTicket 应该是 UCWA 的一个可能的身份验证令牌。
不幸的是,文档仍然正确地说 UCWA 目前仅支持本地安装。对于 Lync Online / Office 365,它尚未启用。
Office 的用户语音上有一个功能请求,您可以投票和关注。如您所见,预计很快就会有公告
https://officespdev.uservoice.com/forums/224641-general/suggestions/5857717-ucwa-for-lync-365
【讨论】:
【参考方案2】:看起来 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;
【讨论】:
以上是关于如何访问 Lync Online (Office 365) 的 UCWA 终结点?的主要内容,如果未能解决你的问题,请参考以下文章
Office 365 轻松上手指南 - Exchange online
如何获取使用Office365 Group Template创建的SharePoint Online Site