IdentityServer not compatible
reservoir-dogs opened this issue · comments
I can't use both :
IdentityServer4 3.1.3
Stashbox.Extensions.Hosting 2.9.0
Can I help me ?
My Startup :
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
var apiResources = new List<ApiResource>
{
new ApiResource("api1", "My API")
};
var clients = new List<Client>
{
new Client
{
ClientId = "client",
// no interactive user, use the clientid/secret for authentication
AllowedGrantTypes = GrantTypes.ClientCredentials,
// secret for authentication
ClientSecrets =
{
new Secret("secret".Sha256())
},
// scopes that client has access to
AllowedScopes = { "api1" }
}
};
services.AddIdentityServer()
.AddInMemoryApiResources(apiResources)
.AddInMemoryClients(clients);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseIdentityServer();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
If i comment the following line in Program.cs, it works :
...
.UseStashbox()
...
To reproduce use my repo :
https://github.com/reservoir-dogs/WebApplicationWithStashBoxAndIdentityServer
Exception is :
System.InvalidOperationException: variable '' of type 'Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider' referenced from scope '', but it is not defined
at System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
at System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node)
at System.Linq.Expressions.ParameterExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitNew(NewExpression node)
at System.Linq.Expressions.NewExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitNew(NewExpression node)
at System.Linq.Expressions.NewExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitNew(NewExpression node)
at System.Linq.Expressions.NewExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
at System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
at System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression`1 node)
at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.Compiler.VariableBinder.Visit(Expression node)
at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda)
at System.Linq.Expressions.LambdaExpression.Compile()
at System.Linq.Expressions.ExpressionExtensions.CompileDelegate(Expression expression, ResolutionContext resolutionContext, ContainerConfiguration containerConfiguration)
at Stashbox.Lifetime.FactoryLifetimeDescriptor.GetNewFactoryDelegate(ExpressionBuilder expressionBuilder, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Lifetime.FactoryLifetimeDescriptor.GetFactoryDelegateForRegistration(ExpressionBuilder expressionBuilder, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Lifetime.FactoryLifetimeDescriptor.BuildLifetimeAppliedExpression(ExpressionBuilder expressionBuilder, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Lifetime.LifetimeDescriptor.ApplyLifetime(ExpressionBuilder expressionBuilder, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Expressions.ExpressionBuilder.BuildExpressionAndApplyLifetime(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Resolution.ResolutionStrategy.BuildExpressionForType(ResolutionContext resolutionContext, TypeInformation typeInformation)
at Stashbox.Expressions.MethodExpressionFactory.TryBuildMethod(MethodBase method, RegistrationContext registrationContext, ResolutionContext resolutionContext, TypeInformation& failedParameter, Expression[]& parameterExpressions)
at Stashbox.Expressions.MethodExpressionFactory.SelectConstructor(RegistrationContext registrationContext, ResolutionContext resolutionContext, ConstructorInfo[] constructors, Expression[]& parameterExpressions)
at Stashbox.Expressions.ExpressionFactory.CreateInitExpression(RegistrationContext registrationContext, ResolutionContext resolutionContext, IEnumerable`1 constructors)
at Stashbox.Expressions.ExpressionFactory.ConstructExpression(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type serviceType)
at Stashbox.Expressions.ExpressionBuilder.PrepareDefaultExpression(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Expressions.ExpressionBuilder.GetExpressionForDefault(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Expressions.ExpressionBuilder.BuildExpressionByRegistrationType(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Expressions.ExpressionBuilder.BuildDisposalTrackingAndFinalizerExpression(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Lifetime.LifetimeDescriptor.GetExpressionForRegistration(ExpressionBuilder expressionBuilder, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Lifetime.ExpressionLifetimeDescriptor.BuildLifetimeAppliedExpression(ExpressionBuilder expressionBuilder, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Lifetime.LifetimeDescriptor.ApplyLifetime(ExpressionBuilder expressionBuilder, ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Expressions.ExpressionBuilder.BuildExpressionAndApplyLifetime(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type resolveType)
at Stashbox.Resolution.ResolutionStrategy.BuildExpressionForTopLevelRequest(Type type, Object name, ResolutionContext resolutionContext)
at Stashbox.ResolutionScope.Activate(ResolutionContext resolutionContext, Type type, Object name)
at Stashbox.ResolutionScope.Resolve(Type typeFrom, Boolean nullResultAllowed, Object[] dependencyOverrides)
at Stashbox.ResolutionScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.AuthenticateAsync(HttpContext context, String scheme)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Hey,
Thanks for reporting! I'm looking into it now!
Hi,
Did you find a solution? or a workaround?
Hey,
Yep, I found the solution, right now I'm fixing the other one you reported, I'm planning to release the fixes in the next 1-2 days.
The fix is released in v3.1.2
I tested it and it works!
Thanks