I need to be able to pass MvcOptions to AddControllersWithViews to setup OIDC authentication on the frontend of my v12.2 site. But, as I understand it AddControllersWithViews is compiled in Umbraco.Web.Common.dll as part of UmbracoBuilderExtensions.cs
Is there a way to override AddControllersWithViews in Startup.cs?
This is what I would typically do in Startup.cs for a typical .NET Core site, but I can't figure out how to do this for a Umbraco v12.2 site...
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(_config.GetSection("AzureAd"));
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
@BrendanRice thanks for the reply! I liked your solution and thought it might just work. Alas, I tried it and got the same error I do when I use the original code.
@BredanRice 100% agree. I was just typing the same thing. Looks like Umbraco gets hung in an infinite loop. I'm not sure where "/account/login" comes from. I setup the App registration in portal.azure.com and specify my localhost redirect URI as https://localhost:44314/signin-oidc
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(_config.GetSection("AzureAd"));
services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
});
And then you add these to Startup.Configure...
app.UseAuthentication();
app.UseAuthorization();
Then what should happen is the website visitor gets prompted with the OIDC login screen and after authenticating against AzureAD they're allowed into the website. That's it.
@brendanrice I don't know where /account/login is coming from. That's not part of my code. I presume it's from Umbraco.
If I had to guess, purely a guess here...but I'm wondering if the app.UseAuth lines causes Umbraco to attempt to call the Umbraco backoffice login page.
How to pass MvcOptions to AddControllersWithViews
I need to be able to pass
MvcOptions
toAddControllersWithViews
to setup OIDC authentication on the frontend of my v12.2 site. But, as I understand itAddControllersWithViews
is compiled in Umbraco.Web.Common.dll as part of UmbracoBuilderExtensions.csIs there a way to override
AddControllersWithViews
in Startup.cs?This is what I would typically do in Startup.cs for a typical .NET Core site, but I can't figure out how to do this for a Umbraco v12.2 site...
Would something like this work:
@BrendanRice thanks for the reply! I liked your solution and thought it might just work. Alas, I tried it and got the same error I do when I use the original code.
Can you increase the query string length in the web.config?
Actually looking at the query string it looks like there is a loop going on with the return URL growing in length each time.
When I say loop, I mean a redirect loop of some sort.
Any idea why?
@BredanRice 100% agree. I was just typing the same thing. Looks like Umbraco gets hung in an infinite loop. I'm not sure where "/account/login" comes from. I setup the App registration in portal.azure.com and specify my localhost redirect URI as https://localhost:44314/signin-oidc
It sounds like a misconfigured redirect URL.
What I think is happening:
Without seeing your code that's just a guess but hopefully one that gets you closer to a solution.
@brendanrice there's not much code to make AzureAD OIDC work on a .NET Core site...
First you register the site in Azure and specify the redirect URI. For this example mine is: https://localhost:44314/signin-oidc
You add this to Startup.ConfigureServices...
And then you add these to Startup.Configure...
Then what should happen is the website visitor gets prompted with the OIDC login screen and after authenticating against AzureAD they're allowed into the website. That's it.
Sorry I'm not that familiar with AzureAD OIDC.
One things that jumps out though is the URL, you say your login URL is:
https://localhost:44314/signin-oidc
Yes this differs from the Requested URL in the 404.15 error message:
https://localhost:44314/Account/Login?ReturnUrl=%2FAccount%2FLogin...
Is this mismatch expected?
@brendanrice I don't know where /account/login is coming from. That's not part of my code. I presume it's from Umbraco.
If I had to guess, purely a guess here...but I'm wondering if the app.UseAuth lines causes Umbraco to attempt to call the Umbraco backoffice login page.
@brendanrice I found this https://docs.umbraco.com/umbraco-cms/tutorials/add-azure-active-directory-authentication
Umbraco login via Azure AD is setup for a multi-tenant Azure AD...ours is a single-tenant Azure AD. I started a new thread addressing that specific issue https://our.umbraco.com/forum/using-umbraco-and-getting-started//113357-umbraco-members-single-tenant-azure-ad-auth
is working on a reply...