From 4784e3e7656faae625560e2de2f922ec93e4908b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 25 Mar 2022 16:24:25 +0300 Subject: [PATCH] Get user's name, surname and phone number from external login, if available. --- .../Claims/AbpClaimActionCollectionExtensions.cs | 14 ++++++++++++++ .../Pages/Account/Login.cshtml.cs | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs index 01dc489c54..2aedea2608 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs @@ -13,6 +13,20 @@ public static class AbpClaimActionCollectionExtensions claimActions.DeleteClaim("name"); claimActions.RemoveDuplicate(AbpClaimTypes.UserName); } + + if (AbpClaimTypes.Name != "given_name") + { + claimActions.MapJsonKey(AbpClaimTypes.Name, "given_name"); + claimActions.DeleteClaim("given_name"); + claimActions.RemoveDuplicate(AbpClaimTypes.Name); + } + + if (AbpClaimTypes.SurName != "family_name") + { + claimActions.MapJsonKey(AbpClaimTypes.SurName, "family_name"); + claimActions.DeleteClaim("family_name"); + claimActions.RemoveDuplicate(AbpClaimTypes.SurName); + } if (AbpClaimTypes.Email != "email") { diff --git a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs index fe94f47415..5ec85d4078 100644 --- a/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs +++ b/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs @@ -277,6 +277,18 @@ public class LoginModel : AccountPageModel CheckIdentityErrors(await UserManager.SetEmailAsync(user, emailAddress)); CheckIdentityErrors(await UserManager.AddLoginAsync(user, info)); CheckIdentityErrors(await UserManager.AddDefaultRolesAsync(user)); + + user.Name = info.Principal.FindFirstValue(AbpClaimTypes.Name); + user.Surname = info.Principal.FindFirstValue(AbpClaimTypes.SurName); + + var phoneNumber = info.Principal.FindFirstValue(AbpClaimTypes.PhoneNumber); + if (!phoneNumber.IsNullOrWhiteSpace()) + { + var phoneNumberConfirmed = string.Equals(info.Principal.FindFirstValue(AbpClaimTypes.PhoneNumberVerified), "true", StringComparison.InvariantCultureIgnoreCase); + user.SetPhoneNumber(phoneNumber, phoneNumberConfirmed); + } + + await UserManager.UpdateAsync(user); return user; }