When using the new .NavigateToLogin in a Blazor app in .NET 7 as recommended here, how do I pass a domain hint when calling NavigateToLogin (or NavigateToLogout)? Or is there a way via setup to make the domain hint be added automatically?
Without the domain hint, my users now have an extra step for both log in and out. (I am using MSAL for Open ID Connect with Azure AD.)
From this page, it appears as though I can new-up a InteractiveRequestOptions object, run options.TryAddAdditionalParameter("domain_hint", "mydomain.com");
, and pass that into Navigation.NavigateToLogin
–but it doesn’t work at all; it is simply ineffective.
2
Answers
From this page, I founds that I can create a
InteractiveRequestOptions
object, runoptions.TryAddAdditionalParameter("domainHint", "mydomain.com");
, and pass that into Navigation.NavigateToLogin, and it works great. Just be careful to usedomainHint
and notdomain_hint
, contrary to several pieces of documentation.I think this issue is still applicable: https://github.com/dotnet/aspnetcore/issues/40046#issuecomment-1042575825 – at least that’s how I solved it. Not sure if there’s a better way to do this.
So, step 1: You add class AuthExtensions:
Then in your program.cs you wire it up like this:
Note that I’m not 100% sure which exact parameter you should be adding.
"hd" is the domain hint parameter for google cloud based domains: https://developers.google.com/identity/openid-connect/openid-connect#hd-param
Based on this guide: https://learn.microsoft.com/en-us/azure/active-directory-b2c/direct-signin?pivots=b2c-user-flow – It looks like the Azure domain hint parameter is either
login_hint
ordomain_hint