There are a lot of articles about the 'invalid_grant' error but I didn't find an answer on my situation.
At first, with Postman I am able to get an access token from /token.svc and use it successfully on the discovery service (with the cduser account).
When I run the .NET webapplication (using the DD4T.Providers.DxaModelService package)I get the following error:
[DataServiceClientException: {"error":"invalid_grant"}]
Microsoft.OData.Client.QueryResult.ExecuteQuery() +478
Microsoft.OData.Client.DataServiceRequest.Execute(DataServiceContext context, QueryComponents queryComponents) +254
[DataServiceQueryException: An error occurred while processing this request.]
Microsoft.OData.Client.DataServiceRequest.Execute(DataServiceContext context, QueryComponents queryComponents) +628
Microsoft.OData.Client.DataServiceQuery`1.GetEnumerator() +22
System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +220
Microsoft.OData.Client.DataServiceQueryProvider.ReturnSingleton(Expression expression) +530
Sdl.Web.ModelService.ModelServiceClient.GetModelServiceUri(String uri) +146
Sdl.Web.ModelService.ModelServiceClient..ctor() +126
DD4T.Providers.DxaModelService.BaseProvider..ctor(IProvidersCommonServices providersCommonServices) +137
lambda_method(Closure , Object[] ) +104
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +270
[DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(DD4T.ContentModel.Contracts.Providers.IProvidersCommonServices)' on type 'TridionPageProvider'. ---> An error occurred while processing this request. (See inner exception for details.)]
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +814
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +269
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +110
[DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = TridionPageProvider (ReflectionActivator), Services = [DD4T.ContentModel.Contracts.Providers.IPageProvider], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An exception was thrown while invoking the constructor 'Void .ctor(DD4T.ContentModel.Contracts.Providers.IProvidersCommonServices)' on type 'TridionPageProvider'. ---> An error occurred while processing this request. (See inner exception for details.) (See inner exception for details.)]
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +433
Autofac.Core.Resolving.InstanceLookup.Execute() +180
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +171
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +119
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +269
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +110
[DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = PageFactory (ReflectionActivator), Services = [DD4T.ContentModel.Factories.IPageFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = TridionPageProvider (ReflectionActivator), Services = [DD4T.ContentModel.Contracts.Providers.IPageProvider], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An exception was thrown while invoking the constructor 'Void .ctor(DD4T.ContentModel.Contracts.Providers.IProvidersCommonServices)' on type 'TridionPageProvider'. ---> An error occurred while processing this request. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)]
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +433
Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator) +155
Autofac.Core.Resolving.InstanceLookup.Execute() +166
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +171
Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() +119
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) +269
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +110
[DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = PageController (ReflectionActivator), Services = [MijnPostNL.Controllers.PageController], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = PageFactory (ReflectionActivator), Services = [DD4T.ContentModel.Factories.IPageFactory], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = Shared, Ownership = OwnedByLifetimeScope ---> An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = TridionPageProvider (ReflectionActivator), Services = [DD4T.ContentModel.Contracts.Providers.IPageProvider], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An exception was thrown while invoking the constructor 'Void .ctor(DD4T.ContentModel.Contracts.Providers.IProvidersCommonServices)' on type 'TridionPageProvider'. ---> An error occurred while processing this request. (See inner exception for details.) (See inner exception for details.) (See inner exception for details.) (See inner exception for details.)]
Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) +433
Autofac.Core.Resolving.InstanceLookup.Execute() +180
Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) +171
Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) +108
Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) +122
Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters) +70
Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(Type serviceType) +95
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +61
[InvalidOperationException: An error occurred when trying to create a controller of type 'MijnPostNL.Controllers.PageController'. Make sure that the controller has a parameterless public constructor.]
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +242
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +103
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +263
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +77
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1122
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +213
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +131
My web.config has the following configuration:
<!-- Configuration of the Discovery Service -->
<add key="discovery-service-uri" value="http://<domain>/discovery.svc" />
<add key="oauth-enabled" value="true" />
<add key="oauth-client-id" value="cduser" />
<add key="oauth-client-secret" value="CDUserP@ssw0rd" />
Do you have any suggestions on how to fix this error?
Update: I had a look at Fiddler and there is no token being requested:
Make sure that the controller has a parameterless public constructor.