microsoft-identity-web: [Question] RequiredScope doesn't work (for web APIs called by daemon apps)
Which version of Microsoft Identity Web are you using?
1.21.1
Where is the issue?
- Web API
- Protected web APIs (validating scopes)
Is this a new or an existing app?
This is a new app or an experiment.
Repro
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class SomeController : ControllerBase
{
[RequiredScope("myScopeName")]
public async Task CreateSomething()
{
return Task.CompletedTask();
}
}
Expected behavior
Request finished with 403 code when pass scope myScopeNameM2M.
Actual behavior
Request finishes with 200 code
Additional context / logs / screenshots / link to code
HttpContext.VerifyUserHasAnyAcceptedScope("myScopeName");
Works as expected.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17
RequiredScopeused to work as expected in this issue until version 1.17.0 of Microsoft.Identityt.Web. It got broken in 1.18.0. See these issues: https://github.com/AzureAD/microsoft-identity-web/issues/1609 https://github.com/AzureAD/microsoft-identity-web/issues/1002.In my case adding
builder.Services.AddRequiredScopeAuthorization()statement to Program.cs made theRequiredScopeattribute work.same issue here I have an access_token which I retieve through a Client from AD, then the client calls my WebAPI.
Currently my access_token has a “scp” attribute of “access_api” however when I add an [RequiredScope(“access_api_admin”)] decorator on a controller action (controller has [Authorize]) and I call the endpoint with the “access_api” scope the action gets executed.
Expected behavior would be an Unauthorized…, yet I am gettin the data which I should not be getting…
The token
The endpoint with requiredScope “access_api_admin”
I feel this should block the request I am making with my access_token since the scope “access_api_admin” is not present in the token…