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

[Feature Request] Enable web APIs called by daemon apps to control tokens without roles claim #707

Closed
jmprieur opened this issue Oct 21, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request fixed
Milestone

Comments

@jmprieur
Copy link
Collaborator

Why?

Is your feature request related to a problem? Please describe.
Microsoft.Identity.Web enforces that a token has scopes (for delegated permissions) or roles (when called by daemon apps), however there is another mechanism: the ACL-based authorization pattern to control tokens without roles claim.

Describe the solution you'd like
Have a way to specify that the application can bypass the following test, to support the ACL-based authorization for the web API called by daemons:

// This check is required to ensure that the web API only accepts tokens from tenants where it has been consented and provisioned.
if (!context.Principal.Claims.Any(x => x.Type == ClaimConstants.Scope)
&& !context.Principal.Claims.Any(y => y.Type == ClaimConstants.Scp)
&& !context.Principal.Claims.Any(y => y.Type == ClaimConstants.Roles)
&& !context.Principal.Claims.Any(y => y.Type == ClaimConstants.Role))
{
throw new UnauthorizedAccessException(IDWebErrorMessage.NeitherScopeOrRolesClaimFoundInToken);
}

Describe alternatives you've considered
None. See the discussion here: #691

Proposed design:

  • Add a new bool property named AllowWebApiToBeAuthorizedByACL in the MicrosoftIdentityOptions, which would be false by default.
  • If this property is true, then avoid throwing in
    // This check is required to ensure that the web API only accepts tokens from tenants where it has been consented and provisioned.
    if (!context.Principal.Claims.Any(x => x.Type == ClaimConstants.Scope)
    && !context.Principal.Claims.Any(y => y.Type == ClaimConstants.Scp)
    && !context.Principal.Claims.Any(y => y.Type == ClaimConstants.Roles)
    && !context.Principal.Claims.Any(y => y.Type == ClaimConstants.Role))
    {
    throw new UnauthorizedAccessException(IDWebErrorMessage.NeitherScopeOrRolesClaimFoundInToken);
    }
@jmprieur jmprieur added the enhancement New feature or request label Oct 21, 2020
@jmprieur
Copy link
Collaborator Author

@jennyf19 @TaranbirBhullar

@jmprieur
Copy link
Collaborator Author

Thanks @TaranbirBhullar for confirming that this works for you.

@jennyf19
Copy link
Collaborator

Included in 1.2.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed
Projects
None yet
Development

No branches or pull requests

2 participants