Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Microsoft.Identity.Web.Resource.RequiredScopeFilter 's constructor could not be located when read config from appsettings #1197

Closed
martooooo opened this issue May 17, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@martooooo
Copy link

martooooo commented May 17, 2021

Which version of Microsoft Identity Web are you using?
Microsoft Identity Web 1.9.2

Where is the issue?
Protected web APIs (validating scopes)

Is this a new or an existing app?
This is a new app or an experiment.

Repro

    [ApiController]
    [Route("[controller]")]
    [RequiredScope(RequiredScopesConfigurationKey = "AzureAd:Scopes")]
    public class WeatherForecastController : ControllerBase
    {
        ...The Code from the Asp.net Core 5.0 Web API Template...
    }

    In appsettings.json
    "AzureAd": {
    "Scopes": "Test.Read"
    }

Expected behavior
We expect an 401 or 403 response, depending on if the user is authenticated / authorized.

Actual behavior
InvalidOperationException: A suitable constructor for type 'Microsoft.Identity.Web.Resource.RequiredScopeFilter' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

However, if we replace the line
[RequiredScope(RequiredScopesConfigurationKey = "AzureAd:Scopes")]
with a hard coding one
[RequiredScope(new string[] { "Test.Read" })]
then the app will work perfectly.

Possible solution
None.

Additional context / logs / screenshots
The above scenario is based on the default asp.net core 5.0 Web API template. We followed the tutorial at https://github.com/AzureAD/microsoft-identity-web/wiki/Web-APIs#verify-scopes-in-web-apis-called-on-behalf-of-users

@martooooo martooooo changed the title [Bug] [Bug] Microsoft.Identity.Web.Resource.RequiredScopeFilter 's constructor could not be located when read config from appsettings May 17, 2021
@jmprieur
Copy link
Collaborator

@martooooo you need to update the Microsoft.Identity.Web NuGet package to the latest version. .NET 5.0 template reference ASP.NET Core 1.1.0.

@jmprieur jmprieur added answered question Further information is requested labels May 25, 2021
@jennyf19
Copy link
Collaborator

closing as answered

@martooooo
Copy link
Author

In our case, the Microsoft.Identity.Web NuGet package is already 1.9.2. But the problem persists.

@jmprieur jmprieur reopened this May 26, 2021
@jmprieur jmprieur added bug Something isn't working and removed answered question Further information is requested labels May 31, 2021
@jmprieur
Copy link
Collaborator

See also #1223

@jmprieur
Copy link
Collaborator

jmprieur commented Jun 2, 2021

@martooooo this is fixed in 1.12.0 released today

@jmprieur jmprieur closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants