diff --git a/ChessCubing.App/Components/SiteMenu.razor b/ChessCubing.App/Components/SiteMenu.razor index 343cf23..dceb6a8 100644 --- a/ChessCubing.App/Components/SiteMenu.razor +++ b/ChessCubing.App/Components/SiteMenu.razor @@ -84,6 +84,8 @@ private string LoginHref => BuildAuthHref("login", EffectiveReturnUrl); private string RegisterHref => BuildAuthHref("register", EffectiveReturnUrl); + private string LoginModalSrc => BuildAuthHref("login", EffectiveReturnUrl, embedded: true); + private string RegisterModalSrc => BuildAuthHref("register", EffectiveReturnUrl, embedded: true); private string LogoutHref => BuildAuthHref("logout", "/"); private string CurrentPath @@ -120,8 +122,16 @@ private bool IsCurrentPage(string[] paths) => paths.Any(path => string.Equals(CurrentPath, path, StringComparison.OrdinalIgnoreCase)); - private static string BuildAuthHref(string action, string returnUrl) - => $"authentication/{action}?returnUrl={Uri.EscapeDataString(returnUrl)}"; + private static string BuildAuthHref(string action, string returnUrl, bool embedded = false) + { + var query = $"returnUrl={Uri.EscapeDataString(returnUrl)}"; + if (embedded) + { + query += "&embedded=1"; + } + + return $"authentication/{action}?{query}"; + } private static string BuildDisplayName(ClaimsPrincipal user) => user.Identity?.Name @@ -141,10 +151,10 @@ } private async Task OpenLoginModal() - => await OpenAuthModalAsync("Se connecter", LoginHref); + => await OpenAuthModalAsync("Se connecter", LoginModalSrc); private async Task OpenRegisterModal() - => await OpenAuthModalAsync("Creer un compte", RegisterHref); + => await OpenAuthModalAsync("Creer un compte", RegisterModalSrc); private async Task OpenAuthModalAsync(string title, string source) { diff --git a/ChessCubing.App/Pages/Authentication.razor b/ChessCubing.App/Pages/Authentication.razor index 7a040a1..cfbfe87 100644 --- a/ChessCubing.App/Pages/Authentication.razor +++ b/ChessCubing.App/Pages/Authentication.razor @@ -5,11 +5,15 @@

Authentification

- @if (IsRegisterAction) + @if (StartsInteractiveFlow) {
- Redirection vers la creation de compte... -

L'inscription se poursuit dans Keycloak, puis vous reviendrez automatiquement dans l'application.

+ @(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 @@ -26,12 +30,25 @@ [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 (!IsRegisterAction) + if (!StartsInteractiveFlow) { return; } @@ -42,7 +59,11 @@ ReturnUrl = NormalizeReturnUrl(ReturnUrl) }; - request.TryAddAdditionalParameter("prompt", "create"); + if (IsRegisterAction) + { + request.TryAddAdditionalParameter("prompt", "create"); + } + Navigation.NavigateToLogin("authentication/login", request); } @@ -60,13 +81,11 @@ _ => null, }; - if (status is null) + if (status is null || !IsEmbeddedFlow) { return; } - await Task.Delay(700); - try { await JS.InvokeVoidAsync("chesscubingAuthModal.notifyParent", status);