oauth2.0 更新到.Net 8后,使用Azure AD身份验证的Blazor webassembly中的深层链接不再起作用

x0fgdtte  于 6个月前  发布在  .NET
关注(0)|答案(1)|浏览(77)

我们在Blazor webassembly应用程序中实现了Azure AD:https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-microsoft-entra-id?view=aspnetcore-6.0(在引入MS Entra后更改了文章)
深度链接开箱即用。但是现在我们升级到.Net 8并升级了所有相关的安全软件包后,用户在登录后总是被重定向到应用程序的根目录。app.razor看起来如下:

<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>

字符串
在RedirectToLogin中,returnUrl设置正确:

@inject NavigationManager Navigation

@code {
   protected override void OnInitialized()
   {
      Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}");
   }
}


我想不出发生了什么变化,更不用说如何解决了,有什么想法吗?

yquaqz18

yquaqz181#

显然,现在有一个NavigateToLogin方法:-/

InteractiveRequestOptions requestOptions =
     new()
     {
        Interaction = InteractionType.SignIn,
        ReturnUrl = Navigation.Uri,
     };
  Navigation.NavigateToLogin("authentication/login", requestOptions);

字符串

相关问题