@page "/authentication/{action}" @inject NavigationManager Navigation @inject IJSRuntime JS

Authentification

@if (StartsInteractiveFlow) {
@(IsRegisterAction ? "Ouverture de la creation de compte..." : "Ouverture de la connexion...")

@(IsRegisterAction ? "Le formulaire Keycloak s'ouvre dans cette fenetre integree." : "Le formulaire de connexion Keycloak s'ouvre dans cette fenetre integree.")

} else { }
@code { [Parameter] public string? Action { get; set; } [SupplyParameterFromQuery(Name = "returnUrl")] public string? ReturnUrl { get; set; } [SupplyParameterFromQuery(Name = "embedded")] public string? Embedded { get; set; } private bool IsRegisterAction => string.Equals(Action, RemoteAuthenticationActions.Register, StringComparison.OrdinalIgnoreCase); private bool IsLoginAction => string.Equals(Action, RemoteAuthenticationActions.LogIn, StringComparison.OrdinalIgnoreCase); private bool IsEmbeddedFlow => string.Equals(Embedded, "1", StringComparison.OrdinalIgnoreCase) || string.Equals(Embedded, "true", StringComparison.OrdinalIgnoreCase); private bool StartsInteractiveFlow => IsEmbeddedFlow && (IsLoginAction || IsRegisterAction); protected override void OnParametersSet() { if (!StartsInteractiveFlow) { return; } var request = new InteractiveRequestOptions { Interaction = InteractionType.SignIn, ReturnUrl = NormalizeReturnUrl(ReturnUrl) }; if (IsRegisterAction) { request.TryAddAdditionalParameter("prompt", "create"); } Navigation.NavigateToLogin("authentication/login", request); } protected override async Task OnAfterRenderAsync(bool firstRender) { if (!firstRender) { return; } var status = Action switch { RemoteAuthenticationActions.LogInCallback => "login-succeeded", RemoteAuthenticationActions.LogOutCallback => "logout-succeeded", _ => null, }; if (status is null || !IsEmbeddedFlow) { return; } try { await JS.InvokeVoidAsync("chesscubingAuthModal.notifyParent", status); } catch { } } private static string NormalizeReturnUrl(string? returnUrl) { if (string.IsNullOrWhiteSpace(returnUrl)) { return "/"; } return returnUrl.StartsWith("/", StringComparison.Ordinal) ? returnUrl : $"/{returnUrl}"; } }