I am trying to get access token from IOrganizationService inside custom workflow.
Below is the logic I'm using to retrieve IOrganisationService in custom workflow:
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
_organizationService = serviceFactory.CreateOrganizationService(context.UserId);
I have tried getting Token through OrganizationServiceProxy by below code:
var proxy = (OrganizationServiceProxy) _organizationService;
var token = proxy.SecurityTokenResponse.Token;
which is also resulting in the same error.
What is the possible way here to get access token in this custom workflow?