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

Setting Access Denied path to Identity.Web.UI Access Denied page #161

Merged
merged 1 commit into from
May 15, 2020

Conversation

pmaytak
Copy link
Contributor

@pmaytak pmaytak commented May 14, 2020

There are two ways to implement the fix. I put related comments in PR. Please give opinion. More info in #117.

Also

@@ -79,7 +80,13 @@ public static class WebAppAuthenticationBuilderExtensions
var b2cOidcHandlers = new AzureADB2COpenIDConnectEventHandlers(openIdConnectScheme, microsoftIdentityOptions);

builder.Services.AddSingleton<IOpenIdConnectMiddlewareDiagnostics, OpenIdConnectMiddlewareDiagnostics>();
builder.AddCookie(cookieScheme);
builder.AddCookie(cookieScheme, options =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option 1.
If the path is not set, we set it to default one of our choice.
Pro The setup is all in one place and the scheme we use is abstracted from the user.
Con If the user doesn't call AddMicrosoftIdentityUI and wants to use the default ASP.NET Core path (/Account/AccessDenied), we'll end up replacing it.
Con We're kind of mixing non-UI logic with UI logic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we don't impose developers to use Microsoft.Identity.Web.UI, the /MicrosoftIdentity/Account/AccessDenied page won't be accessible if they don't use it. I would think that the first Con (If the user doesn't call AddMicrosoftIdentityUI and wants to use the default ASP.NET Core path) is really a Pro, as it calling AddMicrosoftIdentityUI requires Microsoft.Identity.Web.UI to be added.

{
throw new ArgumentNullException(nameof(builder));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option 2.
Set the path inside AddMicrosoftIdentityUI. We need to set the path on the scheme with the same name that we assigned to OpenIdConnectOptions.SignInScheme in AddSignIn. That's why I added a scheme parameter.
Pro UI related code is together.
Con It looks a bit weird passing a cookie scheme to this UI related method.
Con If a user uses a non-default cookie scheme name, they would have to pass it here. A bit fragile.

public static IMvcBuilder AddMicrosoftIdentityUI(this IMvcBuilder builder, string cookieScheme = CookieAuthenticationDefaults.AuthenticationScheme)
{
	if (builder == null)
	{
		throw new ArgumentNullException(nameof(builder));
	}

	builder.ConfigureApplicationPartManager(apm =>
	{
		apm.FeatureProviders.Add(new MicrosoftIdentityAccountControllerFeatureProvider());
	});

	builder.Services.Configure<CookieAuthenticationOptions>(cookieScheme, options =>
	{
		options.AccessDeniedPath = new PathString("/MicrosoftIdentity/Account/AccessDenied");
	});

	return builder;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my prefered option (even if I understand the fragility), because /MicrosoftIdentity/Account/AccessDenied is defined in Microsoft.Identity.Web.UI, which customers are not obliged to use.

We'll document the fragility

Is there a way for us to understand which CookieScheme would have been passed into AddSignIn ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could check the Services here if the cookie or OIDC options were added. But that won't work if AddSignIn is called after this method.

I also tried configuring without the scheme name, which should be the default, but that didn't work.

I did have an idea to maybe use PostConfigure somehow, which is trigged after all of the options are added. Will have to explore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmprieur ConfigureAll works. No need to specify scheme name for this.

@pmaytak pmaytak marked this pull request as ready for review May 14, 2020 08:05
@pmaytak pmaytak requested review from jennyf19 and jmprieur May 14, 2020 08:05
Copy link
Collaborator

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @pmaytak
my preference is Option 2.
I don't think we shoud reference in AddSignIn something which is in a NuGet package that customers don't need to add.

@@ -79,7 +80,13 @@ public static class WebAppAuthenticationBuilderExtensions
var b2cOidcHandlers = new AzureADB2COpenIDConnectEventHandlers(openIdConnectScheme, microsoftIdentityOptions);

builder.Services.AddSingleton<IOpenIdConnectMiddlewareDiagnostics, OpenIdConnectMiddlewareDiagnostics>();
builder.AddCookie(cookieScheme);
builder.AddCookie(cookieScheme, options =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we don't impose developers to use Microsoft.Identity.Web.UI, the /MicrosoftIdentity/Account/AccessDenied page won't be accessible if they don't use it. I would think that the first Con (If the user doesn't call AddMicrosoftIdentityUI and wants to use the default ASP.NET Core path) is really a Pro, as it calling AddMicrosoftIdentityUI requires Microsoft.Identity.Web.UI to be added.

{
throw new ArgumentNullException(nameof(builder));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my prefered option (even if I understand the fragility), because /MicrosoftIdentity/Account/AccessDenied is defined in Microsoft.Identity.Web.UI, which customers are not obliged to use.

We'll document the fragility

Is there a way for us to understand which CookieScheme would have been passed into AddSignIn ?

@pmaytak
Copy link
Contributor Author

pmaytak commented May 14, 2020

@jmprieur Agree that option 2 seems better. I'll update the code to use it and see if, perhaps, there's a way to improve it by using something like PostConfigure.

Copy link
Collaborator

@jmprieur jmprieur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Thanks @pmaytak

@pmaytak pmaytak force-pushed the pmaytak/accessDeniedRouting branch from 2cee598 to 00ec54e Compare May 15, 2020 19:09
@pmaytak pmaytak force-pushed the pmaytak/accessDeniedRouting branch from 00ec54e to db485c7 Compare May 15, 2020 19:11
@pmaytak pmaytak merged commit d21028d into master May 15, 2020
@pmaytak pmaytak deleted the pmaytak/accessDeniedRouting branch May 28, 2020 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants