One of the main things that makes enterprise or intranet applications more lively and connected with your business contacts, is to integrate with Lync (formerly Microsoft Office Communicator) and provide options to interact with them. UCWA(Unified Communications Web Api) is a REST API that exposes Lync Server and its presence capabilities, which can be used to enhance your application capabilities. This can also be used to integrate with Windows phone applications as well and will see how to get started with it here.
To connect to a lync server the only details that we would want is the full email address and the password – thanks to AutoDiscover.aspx) for exchange, which makes this possible. AutoDiscover is the way to find the users home server so that we can connect to it. The url for auto discover, otherwise called the Root Url can take different forms. In this sample I have assumed that it would take the below form, primarily because it works with the test domain that I was using (microsoft.com).
Issuing a get request to ‘https://lyncdiscover.microsoft.com/’, will give the details of the home server that we need to connect to.
1 2 3 4
We now need to authenticate the user with the home server.for which we need the oauth url. This can be obtained by issuing a dummy get request to the user url obtained above. This request will fail with an unauthorized access but also returns the url (https://lync32.lyncweb.microsoft.com/WebTicket/oauthtoken) from which the token needs to be obtained
1 2 3 4 5 6 7 8 9 10 11
UCWA supports Windows Authentication, Anonymous meeting and Password Authentication mechanisms to authorize the user. i am using the Password Authentication here. On successful authentication a token is returned which can be used to issue the get request on the user url with the token in the header.
1 2 3 4 5 6 7 8 9 10 11
A successful request for the above returns the applications url. The applications url might be hosted on a different server in which case we would need to get a separate token for creating a new application. The host of applications url and the oauth url we got above should be same , or else we need to get a new token. When creating a new application, we add the token only if the host’s are same. Not adding this will again fail with Unauthorized exception giving us the new oauth url.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Once this is done we have successfully created an application, that can be used to do a lot more things. As for the sample I have just retrieved the user’s full name, department and title that comes as part of successfully creating an application. You can do a lot more like getting the users presence, image, contacts, join meetings and a lot more.
You can find the sample here.Hope this helps you to build connected enterprise applications.
PS: I have tested this only against microsoft.com domain. In case you find any issues with the domain that you are using please do put it in the comments.