Identityserver4 Blazor WASM IdentityServer 4注销警报

Identityserver4 Blazor WASM IdentityServer 4注销警报,identityserver4,blazor,blazor-webassembly,Identityserver4,Blazor,Blazor Webassembly,我正在使用新的独立Blazor WASM身份验证流和IdentityServer 4。我想向用户提供一条消息,说明他们由于不活动而注销。我已经用一个低质量的js alert()实现了这一功能,但我想知道是否可以用一个自定义的弹出窗口或者一个重定向参数发送到identityserver,在identityserver登录页面上向他们显示警报 我不太明白如何中断onlogoutsuccessed之后发生的立即重定向。js alert()暂停重定向并工作。我是否可以修改传出登录重定向uri以向IDS4

我正在使用新的独立Blazor WASM身份验证流和IdentityServer 4。我想向用户提供一条消息,说明他们由于不活动而注销。我已经用一个低质量的js alert()实现了这一功能,但我想知道是否可以用一个自定义的弹出窗口或者一个重定向参数发送到identityserver,在identityserver登录页面上向他们显示警报

我不太明白如何中断onlogoutsuccessed之后发生的立即重定向。js alert()暂停重定向并工作。我是否可以修改传出登录重定向uri以向IDS4提供一个参数

<RemoteAuthenticatorView Action="@Action" OnLogOutSucceeded="LogoutSucceeded">
</RemoteAuthenticatorView>

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

    private async Task LogoutSucceeded()
    {
        await JsInterop.InvokeVoidAsync("alert", "You have been logged out due to inactivity.");
    }
}

@代码{
[参数]公共字符串操作{get;set;}
私有异步任务LogoutSuccessed()
{
等待JsInterop.InvokeVoidAsync(“警报”,“您因不活动而注销”);
}
}
我想出来了:

//program.cs
  builder.Services.AddOidcAuthentication<ApplicationAuthenticationState>(options =>
            {
                //options
            });

//Authentication.razor
<RemoteAuthenticatorViewCore Action="@Action"
                             TAuthenticationState="ApplicationAuthenticationState"
                             OnLogOutSucceeded="LogoutSucceeded"
                             AuthenticationState="AuthState" />

 [Parameter]
    public string Action { get; set; }

    public ApplicationAuthenticationState AuthState { get; set; } = new ApplicationAuthenticationState();

    public bool Idled { get; set; }

    protected override void OnInitialized()
    {
        if (RemoteAuthenticationActions.IsAction(RemoteAuthenticationActions.LogOut, Action))
        {
            var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
            if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("idle", out var param))
            {
                AuthState.Idle = !string.IsNullOrWhiteSpace(param);
            }
        }
    }

  private void LogoutSucceeded(ApplicationAuthenticationState state)
    {
        Idled = state.Idle;
        if (Idled)
        {
             // save redirect for later
            var returnUrl = state.ReturnUrl;
            // cancel redirect
            state.ReturnUrl = null;

              // implement custom flow
        }
    }
//program.cs
builder.Services.AddOidcAuthentication(选项=>
{
//选择权
});
//身份验证.razor
[参数]
公共字符串操作{get;set;}
公共ApplicationAuthenticationState AuthState{get;set;}=new ApplicationAuthenticationState();
公共bool空闲{get;set;}
受保护的覆盖无效OnInitialized()
{
if(RemoteAuthenticationActions.IsAction(RemoteAuthenticationActions.LogOut,Action))
{
var uri=NavManager.ToAbsoluteUri(NavManager.uri);
if(QueryHelpers.ParseQuery(uri.Query.TryGetValue(“idle”,out var param))
{
AuthState.Idle=!string.IsNullOrWhiteSpace(param);
}
}
}
私有void注销成功(ApplicationAuthenticationState)
{
空闲=状态。空闲;
如果(怠速)
{
//保存重定向供以后使用
var returnUrl=state.returnUrl;
//取消重定向
state.ReturnUrl=null;
//实现自定义流
}
}
我想出来了:

//program.cs
  builder.Services.AddOidcAuthentication<ApplicationAuthenticationState>(options =>
            {
                //options
            });

//Authentication.razor
<RemoteAuthenticatorViewCore Action="@Action"
                             TAuthenticationState="ApplicationAuthenticationState"
                             OnLogOutSucceeded="LogoutSucceeded"
                             AuthenticationState="AuthState" />

 [Parameter]
    public string Action { get; set; }

    public ApplicationAuthenticationState AuthState { get; set; } = new ApplicationAuthenticationState();

    public bool Idled { get; set; }

    protected override void OnInitialized()
    {
        if (RemoteAuthenticationActions.IsAction(RemoteAuthenticationActions.LogOut, Action))
        {
            var uri = NavManager.ToAbsoluteUri(NavManager.Uri);
            if (QueryHelpers.ParseQuery(uri.Query).TryGetValue("idle", out var param))
            {
                AuthState.Idle = !string.IsNullOrWhiteSpace(param);
            }
        }
    }

  private void LogoutSucceeded(ApplicationAuthenticationState state)
    {
        Idled = state.Idle;
        if (Idled)
        {
             // save redirect for later
            var returnUrl = state.ReturnUrl;
            // cancel redirect
            state.ReturnUrl = null;

              // implement custom flow
        }
    }
//program.cs
builder.Services.AddOidcAuthentication(选项=>
{
//选择权
});
//身份验证.razor
[参数]
公共字符串操作{get;set;}
公共ApplicationAuthenticationState AuthState{get;set;}=new ApplicationAuthenticationState();
公共bool空闲{get;set;}
受保护的覆盖无效OnInitialized()
{
if(RemoteAuthenticationActions.IsAction(RemoteAuthenticationActions.LogOut,Action))
{
var uri=NavManager.ToAbsoluteUri(NavManager.uri);
if(QueryHelpers.ParseQuery(uri.Query.TryGetValue(“idle”,out var param))
{
AuthState.Idle=!string.IsNullOrWhiteSpace(param);
}
}
}
私有void注销成功(ApplicationAuthenticationState)
{
空闲=状态。空闲;
如果(怠速)
{
//保存重定向供以后使用
var returnUrl=state.returnUrl;
//取消重定向
state.ReturnUrl=null;
//实现自定义流
}
}