Sharepoint 2013 Microsoft.Office.SecureStoreService.dll

The Microsoft.Office.SecureStoreService.dll is needed if you want to programmatically retrieve credentials from SSS. In SPS 2013 (windows server 2012) you can find this dll in:

c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.SecureStoreService\v 4.0_15.0.0.0__71e9bce111e9429c

You can use cmd to navigate to that directory and copy the dll to use as a reference in your Visual Studio Project.

(more info:

http://msdn.microsoft.com/en-us/library/ff394459(v=office.14).aspx

http://msdn.microsoft.com/en-us/library/microsoft.office.securestoreservice.server.securestoreproviderfactory.aspx)

The sample code to retrive credentials (the applicationId is a property in my webpart and it is the value of a SSS application created in Central Administration, Secure Store Service):

private void MyWebPart_Load(object sender, EventArgs e)
 {
   if (!String.IsNullOrEmpty(applicationId))
   {
     // Get the default Secure Store Service provider.
     ISecureStoreProvider provider = SecureStoreProviderFactory.Create();
     if (provider == null)
     {
       throw new InvalidOperationException("Unable to get an ISecureStoreProvider");
     }
     ISecureStoreServiceContext providerContext = provider as       ISecureStoreServiceContext;
     providerContext.Context = SPServiceContext.Current;
     try
     {
      using (SecureStoreCredentialCollection creds = provider.GetCredentials (ApplicationId))
      {
        Debug.Assert(creds != null);

        if (creds != null)
        {
         foreach (SecureStoreCredential cred in creds)
         {
           if (cred == null)
           {
            continue;
           }

          switch (cred.CredentialType)
          {
           case SecureStoreCredentialType.UserName:
           case SecureStoreCredentialType.WindowsUserName:
           if (username == null)
           {
            username = GetStringFromSecureString(cred.Credential);
           }
           break;
           case SecureStoreCredentialType.WindowsPassword:
           case SecureStoreCredentialType.Password:
           if (password == null)
           {
            password = GetStringFromSecureString(cred.Credential);
           }
           break;
         } //switch
       }//foreach
      }//if
    }//using
   if (username == null || password == null)
   {
    throw new InvalidOperationException("Unable to get the credentials");
   }
   this.mustSetCredentials = false;
  }//try
  catch (SecureStoreException ex)
  {
    Debug.WriteLine(ex.Message);
    this.mustSetCredentials = true;
    //throw;
   }
  }
 }

 
Advertisements

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: