From 11aaa41bfd71aaa226d41b10ad23127961f256f9 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Tue, 26 Nov 2024 18:08:39 +0800 Subject: [PATCH] fix: fix sign-in parameter \'identifier\' --- samples/sample-blazor/Program.cs | 6 +++--- samples/sample-mvc/Controllers/HomeController.cs | 3 +-- samples/sample/Pages/Index.cshtml.cs | 3 +-- .../extensions/AuthenticationBuilderExtensions.cs | 8 +++++++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/samples/sample-blazor/Program.cs b/samples/sample-blazor/Program.cs index 6022c9a..be3ed15 100644 --- a/samples/sample-blazor/Program.cs +++ b/samples/sample-blazor/Program.cs @@ -54,12 +54,12 @@ /// /// - authProperties.SetParameter("first_screen", LogtoParameters.Authentication.FirstScreen.Register); + authProperties.SetParameter("first_screen", LogtoParameters.Authentication.FirstScreen.SignIn); - // This parameter MUST be used together with `first_screen`. - authProperties.SetParameter("identifiers", string.Join(",", new[] + authProperties.SetParameter("identifiers", System.Text.Json.JsonSerializer.Serialize(new[] { LogtoParameters.Authentication.Identifiers.Username, + LogtoParameters.Authentication.Identifiers.Email, })); var directSignIn = new LogtoParameters.Authentication.DirectSignIn diff --git a/samples/sample-mvc/Controllers/HomeController.cs b/samples/sample-mvc/Controllers/HomeController.cs index b0c813d..a657538 100644 --- a/samples/sample-mvc/Controllers/HomeController.cs +++ b/samples/sample-mvc/Controllers/HomeController.cs @@ -35,8 +35,7 @@ public IActionResult SignIn() /// authProperties.SetParameter("first_screen", LogtoParameters.Authentication.FirstScreen.Register); - // This parameter MUST be used together with `first_screen`. - authProperties.SetParameter("identifiers", string.Join(",", new[] + authProperties.SetParameter("identifiers", JsonSerializer.Serialize(new[] { LogtoParameters.Authentication.Identifiers.Username, })); diff --git a/samples/sample/Pages/Index.cshtml.cs b/samples/sample/Pages/Index.cshtml.cs index 1a94fc1..32d77ff 100644 --- a/samples/sample/Pages/Index.cshtml.cs +++ b/samples/sample/Pages/Index.cshtml.cs @@ -32,8 +32,7 @@ public async Task OnPostSignInAsync() /// authProperties.SetParameter("first_screen", LogtoParameters.Authentication.FirstScreen.Register); - // This parameter MUST be used together with `first_screen` - authProperties.SetParameter("identifiers", string.Join(",", new[] + authProperties.SetParameter("identifiers", JsonSerializer.Serialize(new[] { LogtoParameters.Authentication.Identifiers.Username, })); diff --git a/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs b/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs index 2688a3d..2b3080c 100644 --- a/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs +++ b/src/Logto.AspNetCore.Authentication/extensions/AuthenticationBuilderExtensions.cs @@ -111,7 +111,13 @@ private static void ConfigureOpenIdConnectOptions(OpenIdConnectOptions options, if (context.Properties.Parameters.TryGetValue("identifiers", out var identifiers)) { - context.ProtocolMessage.Parameters.Add("identifiers", identifiers?.ToString()); + var identifierArray = System.Text.Json.JsonSerializer.Deserialize( + identifiers?.ToString() ?? "[]" + ); + if (identifierArray?.Length > 0) + { + context.ProtocolMessage.Parameters.Add("identifier", string.Join(" ", identifierArray)); + } } if (context.Properties.Parameters.TryGetValue("direct_sign_in", out var directSignIn))