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!