We implemented Azure AD in our Blazor webassembly app following this article: https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-microsoft-entra-id?view=aspnetcore-6.0 (article changed after introduction of MS Entra)
And deep linking worked out of the box. But now after we upgrade to .Net 8 and upgraded all related security packages the user is always redirected to the root of the application after login. The app.razor looks as follows:
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true) {
<RedirectToLogin/>
}
else {
<p role="alert">@_localizer["Globaal.NietGeautoriseerd"]</p>
}
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p style="text-align: center; margin-top: 50px;" role="alert">@_localizer["Globaal.PaginaNietGevonden"]</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
and in the RedirectToLogin the returnUrl is set correctly:
@inject NavigationManager Navigation
@code {
protected override void OnInitialized()
{
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}");
}
}
I can't figure out what has changed let alone how to solve it, any idea?
Apparently there now is a NavigateToLogin method :-/
InteractiveRequestOptions requestOptions =
new()
{
Interaction = InteractionType.SignIn,
ReturnUrl = Navigation.Uri,
};
Navigation.NavigateToLogin("authentication/login", requestOptions);