我的Blazor应用程序在https://localhost:5001/app上运行

但在我登录后,AUTHO总是返回到https://localhost:5001

我怎么才能改变这一点呢?

以下是我如何注册该服务:

builder.Services.AddOidcAuthentication(options =>
{
    builder.Configuration.Bind("Auth0", options.ProviderOptions);
    options.ProviderOptions.DefaultScopes.Add("email");
    options.ProviderOptions.AdditionalProviderParameters.Add("audience", (string)builder.Configuration["Auth0:Audience"]!);
    options.ProviderOptions.AdditionalProviderParameters.Add("prompt", "select_account");
    // options.ProviderOptions.AdditionalProviderParameters.Add("returnTo", "https://localhost:5001/app"); <== NOT WORKING
});

下面是我的身份验证组件:

@page "/app/authentication/{action}"

@using Microsoft.Extensions.Configuration
@inject NavigationManager Nav

<RemoteAuthenticatorView Action="@Action" OnLogInSucceeded=@loginHandler OnLogOutSucceeded=@logoutHandler>
    <LogOut>
        @{
            var authority = (string)Configuration["Auth0:Authority"]!;
            var clientId = (string)Configuration["Auth0:ClientId"]!;
            var returnTo = "https://localhost:5001/app";
            Nav.NavigateTo($"{authority}/v2/logout?client_id={clientId}&returnTo={returnTo}");
        }
    </LogOut>
</RemoteAuthenticatorView>

@code {
    [Parameter]
    public string? Action { get; set; }

    private void loginHandler() {}
    private void logoutHandler() {}
}

推荐答案

您可以try 如下所示:

builder.Services.AddOidcAuthentication(options =>
{
    options.ProviderOptions.RedirectUri = "{Your target url}";
    
});

我转载了这个问题:

enter image description here

根据RBee的 comments 解决了这个问题(RemoteAuthenticatorView组件默认情况下会将您重定向到"/",为了避免这种情况,您必须将forceload设置为True):

@page "/app/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inject NavigationManager Nav

<RemoteAuthenticatorView Action="@Action" OnLogInSucceeded="@LoginSucceeded" />

@code {
    [Parameter]
    public string? Action { get; set; }
    

    

    public void LoginSucceeded()
    {
        Nav.NavigateTo("/app",true);
    }

    
}

现在可以了:

enter image description here

Csharp相关问答推荐

Inbox RandomizedStringHashAl算法如何帮助抵御哈希洪泛攻击?

更新数据库中的对象失败,原因是:Microsoft. EntityFrame Core. GbUpdateConcurrencyResponse'

总是丢弃返回的任务和使方法puc无效之间有区别吗?

更改对象的旋转方向

有没有办法把+02:00转换成TimeSpan?""

有没有办法在WPF文本框中添加复制事件的处理程序?

C#EF Core WHERE IN LINQ FROM LIST WITH.CONTAINS不返回任何内容

Take()方法如何与IAsyncEnumerable一起使用

如何使用MoQ模拟Resources GroupCollection?

如何使用用于VS代码的.NET Maui扩展在我的iOS/Android设备或模拟器上进行调试?

记录类型';==运算符是否与实现IEquatable<;T&>;的类中的';equals&>方法执行等价比较?

VS 2022与VS 2019:如何/为什么创建额外的任务?

Azure Functions v4中的Serilog控制台主题

在';、';附近有错误的语法.必须声明标量变量";@Checkin";.';

多个选项卡上的MudForm验证

毛伊岛.NET 8图片不再适合按钮

在C#中通过Matheval使用自定义公式

Xamarin中出错.表单:应用程序的分部声明不能指定不同的基类

在.Net 8 Visual Studio 2022中启用本机AOT发布时发布失败

最小API定义的Swagger标头参数