Word add-in: retrieve user credentials that were used to open a document from SharePoint

We are developing a Word add-in in C # and WPF.

Documents are opened from SharePoint, which live in a different domain, and are processed using an add-in. When the document opens, MS Word asks for credentials for the SharePoint domain.

In the Word add-in, I need to get these credentials or any security token in order to install it using SharePoint.

When I try to use CredentialsCache with C #, I get the credentials for the local Windows account / domain, but not for the Sharepoint domain account.

I understand that Word stores credentials for SharePoint, as I can register / verify and save without re-entering the password.

But can I somehow get these credentials from the code to access SharePoint services without asking for the password again?

+4
source share
1 answer

If the called web service uses the built-in protection for Windows, creating a NetworkCredential from the current WindowsIdentity should be sufficient for the web service to use the Windows user account. However, if the web service uses a different security model, there is no way to extract the user's password from the current authentication ... which in itself will be insecure, which will allow you, the developer, to steal your user passwords. You probably need to provide some way provide your password for your user and save it in some kind of secure cache if you do not want them to provide it repeatedly.

Edit: To get the credentials for the current identifier, use the following:

Uri uri = new Uri("http://tempuri.org/"); ICredentials credentials = CredentialCache.DefaultCredentials; NetworkCredential credential = credentials.GetCredential(uri, "Basic"); 
+1
source

All Articles