Is there a way to pass the credentials of the current windows user into LyncClient.Submit()

2k views Asked by At

I am creating an In/Out system tray application that interacts with the Microsoft Lync Server through the Microsoft Lync API. Is there a way to pass the username and password of the current windows user to the Lync API so users will be automatically logged in instead of having them enter the credentials every time?

1

There are 1 answers

0
Paul Nearney On BEST ANSWER

No, unlike e.g. accessing a web service, there is no way to force Lync to use the logged-on users credentials. You can see this with the Lync client itself the first time you run it on your machine - you will be prompted for domain credentials, even if you are logged on to the machine as a domain user.

All is not lost, though, as Lync (by default) will save credentials as they are entered, and then present them back to the server each time it logs on as that user. You can check to see if Lync is set to save passwords in the registry:

[HKEY_CURRENT_USER\Software\Microsoft\Communicator]
"SavePassword"=dword:00000001

To take advantage of this in the API, you need to:

  1. Initialise the client in the usual way
  2. Register for the lyncClient.CredentialRequested event
  3. Call lyncClient.BeginSignIn, passing the sip uri of the user logging on (the lyncClient.Uri property is usually set to the uri of the user that last logged on, for convenience). Pass null for the username and password.

Now - if your user has not logged in to Lync (or your app) previously, you will get a CredentialRequested event.

  1. Cancel the event using CredentialRequestedEventArgs.Cancel()
  2. Show some UI to collect the username and password from the user, then call BeginSignIn with these credentials
  3. Alternatively, call BeginSignIn with null username and password, then handle CredentialRequested, and submit the credentials to the server using the Submit method in the CredentialRequestedEventArgs (the last parameter in the Submit method must be set to True to save the password)

(I can't remember off the top of my head which method out of 2 or 3 above is the recommended approach - best to try both and see which you have most luck with)

Next time that user logs in (assuming SavePassword is set to true in the registry), the saved credentials will be passed, so user will log in without the CredentialRequested event firing.

This MSDN article covers the process quite nicely (I'm assuming that you're running Lync in UI Supressed mode, as this is only an issue in suppressed mode)