Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
Thanks for the idea, but I understood the Timer Job service should run under a "least privileges" user. Would that "break" that? –  SPDuFeu Oct 8 '12 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 '12 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! –  SPDuFeu Oct 9 '12 at 13:56
    
Added less dirty answer. –  Jussi Palo Apr 7 at 10:18

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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