ScopeRequirementMiddleware has a ctor which expects a string array of scopes (string[])
while IdentityServerBearerTokenAuthenticationOptions exposes the above mentioned scopes as an IEnumerable (these scopes from the option class are further used in your code to determine whether or not to inject the ScopeRequirementMiddleware in the pipeline)
This means that you expect to assign an array of strings (string[]) with an IEnumerable... which I don't think you will succeed :)... (only the other way around is possible)
Getting back to your code
below code will work OK
var authOptions =
new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44333",
RequiredScopes = new[] { "api1" }
});
app.UseIdentityServerBearerTokenAuthentication(authOptions);
This will work due to the fact that even though RequiredScopes is an IEnumerable, you instantiate it with an array of strings; this means that
typeof(string[]).IsInstanceOf(authOptions.RequiredScopes) = TRUE
However, if one would use the IEnumerable like it was meant to be used, meaning using yield operator... surprise, surprise: MissingMethodException on ScopeRequirementMiddleware (no ctor was found that takes 2 params)
The error comes from Owin, which looks for a matching ctor for a Middleware, by checking its params.
You have an inconsistency in your code:
This means that you expect to assign an array of strings (string[]) with an IEnumerable... which I don't think you will succeed :)... (only the other way around is possible)
Getting back to your code
This will work due to the fact that even though RequiredScopes is an IEnumerable, you instantiate it with an array of strings; this means that
typeof(string[]).IsInstanceOf(authOptions.RequiredScopes) = TRUE
typeof(string[]).IsInstanceOf(authOptions.RequiredScopes) = FALSE -> thus no ctor matching
PS: Owin casts the params of the middleware to an object array