I have a Web API and a frontend application.
In the API permissions of the frontend application, I added a permission to my API (Files.Download).
In the Expose an API of the Web API I have authorized the client application for this scope.
Now, in order to check if the calling application has the required scope, I call the following code from my controller action method :
public static void VerifyUserHasAnyAcceptedScope(this HttpContext context,
params string[] acceptedScopes)
{
if (acceptedScopes == null)
{
throw new ArgumentNullException(nameof(acceptedScopes));
}
Claim scopeClaim = context?.User?.FindFirst("http://schemas.microsoft.com/identity/claims/scope");
if (scopeClaim == null || !scopeClaim.Value.Split(' ').Intersect(acceptedScopes).Any())
{
context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
string message = $"The 'scope' claim does not contain scopes '{string.Join(",", acceptedScopes)}' or was not found";
throw new HttpRequestException(message);
}
}
What I have noticed though, if I don't authorize the frontend application in the Expose an API, then the scope is not part of the claims.
So what is the point of the API Permissions ? I don't get it, it seems redundant and at the same time useless since it has no effetcs;

