0

I'm creating a timer job that polls an RSS feed that requires a username and password. I'd like to store the login credentials in the Secure Store Service.

I believe I have successfully set this up and can retrieve the credentials using the following code:

ISecureStoreProvider provider = SecureStoreProviderFactory.Create();
ISecureStoreServiceContext providerContext = provider as ISecureStoreServiceContext;
SPSite centralAdminSite = GetCentralAdminSite();    // function that gets the ca site
providerContext.Context = SPServiceContext.GetContext(centralAdminSite);

using (SecureStoreCredentialCollection creds = provider.GetCredentials(applicationId))
{
    // code that obtains the username and password omitted
}

The problem is, when I put this code in a TimerJob I get an error:

Credentials were not found for the current user within the target application 'XXXXX'. Please set the credentials for the current user.

I guess this is because the TimerJob is running as "System Account" where as the console application runs as "sp_admin" (the user who created and configured the Secure Store Service).

How do I over come this so I can retrieve the credentials from the Secure Store please?

Should I be storing the credentials in the Secure Store or is that overkill?

Any help would be greatly appreciated!

2 Answers 2

0

Have you tried setting up the credentials in the Secure Store for the user specifically running the timer job? If you go to the Control Panel -> Administrative Tools -> Services and find the SharePoint Timer Service, the user in the 'Log On As' column should be the user you setup the credentials for.

4
  • Thanks for the idea, but I understood the Timer Job service should run under a "least privileges" user. Would that "break" that?
    – MattDuFeu
    Oct 8, 2012 at 10:46
  • As far as I know, the timer service needs to run as the database access account. See the 'Farm Service Account' section here: technet.microsoft.com/en-us/library/cc678863.aspx
    – CMN
    Oct 8, 2012 at 23:56
  • That works, thank you, so I've accepted the answer. Feels "dirty" though, but I guess the machine has a lot of other problems if this is compromised!
    – MattDuFeu
    Oct 9, 2012 at 13:56
  • Added less dirty answer.
    – Jussi Palo
    Apr 7, 2015 at 10:18
0

Better way is to configure the "Target Application Type" as Group, and defining the SharePoint Timer Service account in the Members field.

This way Timer Jobs can access the credentials without the hassle of having to create "Individual" Secure Store Credentials - credentials for those are not really meant to be defined beforehand by the administrator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.