Symptoms
The customer reported that they have built a workflow using K2 Designer for SharePoint and whenever they tried to deploy it to the DEV environment (from the Designer), the following error was thrown:
The "SourceCode.SharePoint15.DeploymentTask.Task" task failed unexpectedly.
System.Exception: Service: SharePointIntegration
Service Guid: 71810da1-81e2-4f22-8cf2-4011dacfdf42
Severity: Error
Error Message: Thread 1: OAuth token requires authorization.
InnerException Message:
at SourceCode.SharePoint15.Utilities.Common.HandleSmartObjectException(SmartObjectException smartObjectException)
at SourceCode.SharePoint15.WorkflowIntegration.WorkflowIntegrationManager.RegisterRemoteEventReceivers(String siteURL, Guid listId, String eventReceiverTypes, String remoteEventReceiverURL)
at SourceCode.SharePoint15.DeploymentTask.Task.ExecuteInternal()
at SourceCode.SharePoint15.DeploymentTask.Task.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
Diagnoses
I've logged on to the customer's DEV environment to have a look at the OAuth tokens on the Management Form.
By doing so I've seen that the K2 DEV Service Account had multiple OAuth token with the type "SharePoint" - see attached screenshot DuplicateOAuthTokens.png.
I've removed these tokens using the Management Form.
Apart from the duplicate tokens, we've seen that the K2 DEV Service account did not have any permissions on the SP Site, could not even access it, so we've granted it SC admin permissions.
After having done that, I've restarted the K2 Blackpearl service on the server, cleared the IE cache of the K2 Service account, reopened IE and navigated to the SP site using the K2 service account's credentials and reran the registration wizard of the K2 for SP App.
By doing so the App forced me to re-trust the App on the site and the registration wizard ran through successful.
Once the registration wizard was through the deployment was also successful and the error disappeared.
Resolution
1. Deleted the duplicate OAuth tokens of the K2 service account using the Management Form
2. Granted the K2 Service Account SC Admin permissions on the SP Site
3. Reran the Registration wizard on the SP Site using the K2 Service Account's credentials