我在IdentityServer4中使用新的独立Blazor WASM身份验证流程。我想向用户提供一条消息,告知他们由于不活动而被注销。我已经可以使用低质量的js alert()来实现此功能,但是我想知道是否可以通过自定义弹出窗口或发送给Identityserver的重定向参数使它们在Identityserver登录页面上显示警报的方式来实现此功能。
我不太想办法中断OnLogoutSucceeded之后发生的立即重定向。 js alert()暂停重定向并起作用。我可以修改传出的登录重定向uri来为IDS4提供参数吗?
package main
import (
"log"
"net/http"
)
type Server struct {
listenPort string
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
router := http.NewServeMux()
router.HandleFunc("/download", s.downloadHandler)
router.ServeHTTP(w, r)
}
func (s *Server) downloadHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w,r, "file.tar.xz")
}
func main(){
s := &Server{listenPort: ":8080"}
if err := http.ListenAndServe(s.listenPort, s); err != nil {
log.Fatalf("could not listen on port %s: %v", s.listenPort, err)
}
}
答案 0 :(得分:0)
我知道了:
//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
}
}