question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] AccessDenied Routing

See original GitHub issue

Which Version of Microsoft Identity Web are you using ? Microsoft.Identity.Web - v0.1.0 Preview Microsoft.Identity.Web.UI - v0.1.0 Preview

Where is the issue?

  • Web App
    • Sign-in users
    • Sign-in users and call web APIs
  • Web API
    • Protected web APIs (Validating tokens)
    • Protected web APIs (Validating scopes)
    • Protected web APIs call downstream web APIs
  • Token cache serialization
    • In Memory caches
    • Session caches
    • Distributed caches

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

Repro

Clone and run the below sample project.

https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/blob/master/5-WebApp-AuthZ/5-2-Groups

Log in with an unauthorized account.

Expected behavior Unauthorized account should be redirected to /MicrosoftIdentity/Account/AccessDenied.

Actual behavior Unauthorized account is redirected to /Account/AccessDenied which doesn’t exist.

Possible Solution The Microsoft.Identity.Web.UI AccountController exists in the MicrosoftIdentity area but there doesn’t seem to be a way to provide the AccessDenied response with this route info.

I’d expect this to be configurable using something like the AccessDenied property like this but it doesn’t seem to work.

services.Configure<OpenIdConnectOptions>(options =>
{
	// Use the groups claim for populating roles
	options.TokenValidationParameters.RoleClaimType = "groups";
	options.AccessDeniedPath = "/MicrosoftIdentity/Account/AccessDenied";
});

Possibly this is a redirect URL that should be set in the portal but it’s not obvious where this is.

A workaround is to create an account controller with the required view but this goes against the point of Microsoft.Identity.Web.UI.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pmaytakcommented, May 13, 2020

Yes, seems like specifying AccessDeniedPath on OpenIdConnectOptions doesn’t work.

Specifying the path on CookieAuthenticationOptions works:

services.Configure<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme, options => {
    options.AccessDeniedPath = new PathString("/MicrosoftIdentity/Account/AccessDenied");
});

The scheme has to be the same as what is passed into AddSignIn method (or default CookieAuthenticationDefaults.AuthenticationScheme) because that is what is passed in https://github.com/AzureAD/microsoft-identity-web/blob/4458dbf15ddf494c2f3f5a27da873260bbe71040/src/Microsoft.Identity.Web/WebAppAuthenticationBuilderExtensions.cs#L82

From logging we can see that when the user is unauthorized and the code above is not used, cookie and OIDC handlers fail and redirect to /Account/AccessDenied... is done. image

When the above fix is used, after the handlers fail to authorize, the redirect is made to a correct page. image

I looked through the ASP.NET Core repo and really the only references to AccessDeniedPath I found were related to cookies.

The default path value is in CookieAuthenticationDefaults.

If the custom path is not specified, it is set to default in PostConfigureCookieAuthenticationOptions PostConfigure.

CookieAuthenticationHandler builds the URI and redirects in HandleForbiddenAsync.

0reactions
jennyf19commented, Jun 1, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting 403 Access Denied Errors When Hosting a React ...
When I deployed a React Router app to AWS S3 and CloudFront and when I try to access React routes directly it gives...
Read more >
Error: "AccessDeniedException"
You get an Access Denied exception when trying to share a resource or view a resource share. You can receive this error if...
Read more >
Resolve Access Denied errors from a CloudFront ...
To troubleshoot Access Denied errors, first determine if your distribution's origin domain name is an S3 website endpoint or an S3 REST API...
Read more >
Access Denied error when using an S3 static website ...
If a user performing the request doesn't have s3:ListBucket permissions, then the user gets an Access Denied error for missing objects. You can...
Read more >
Redirecting on Access Denied fails - Microsoft Q&A
I am trying to point other applications to that access denied page ... EndpointRoutingMiddleware: Debug: Request did not match any endpoints.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found