Starts in:
0 DAY
10 HRS
18 MIN
57 SEC
Starts in:
0 D
10 H
18 M
57 S

Activities of "daxabhudia"

updated OnGetExternalLoginCallbackAsync with the code to update name, surname and phone number when user logs in. It is working ok and able to update the local db.

 public override async Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetExternalLoginCallbackAsync(string returnUrl = "", string returnUrlHash = "", string remoteError = null)
        {
            var loginInfo = await SignInManager.GetExternalLoginInfoAsync();

            if (loginInfo == null)
            {
                return RedirectToPage("./Login");
            }

            var result = await SignInManager.ExternalLoginSignInAsync(
                loginInfo.LoginProvider,
                loginInfo.ProviderKey,
                isPersistent: false,
                bypassTwoFactor: true
            );

            if (!result.Succeeded)
            {
                await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
                {
                    Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
                    Action = "Login" + result
                });
            }

            if (result.IsLockedOut)
            {
                throw new UserFriendlyException("Cannot proceed because user is locked out!");
            }

            if (result.IsNotAllowed)
            {
                throw new UserFriendlyException("Cannot proceed because user is not allowed!");
            }

            if (result.Succeeded)
            {
                var user = await UserManager.FindByLoginAsync(loginInfo.LoginProvider, loginInfo.ProviderKey);
                user.Name = loginInfo.Principal.FindFirstValue(AbpClaimTypes.Name);
                user.Surname = loginInfo.Principal.FindFirstValue(AbpClaimTypes.SurName);
                var phoneNumber = loginInfo.Principal.FindFirstValue(AbpClaimTypes.PhoneNumber);
                if (!phoneNumber.IsNullOrWhiteSpace())
                {
                    var phoneNumberConfirmed =         string.Equals(loginInfo.Principal.FindFirstValue(AbpClaimTypes.PhoneNumberVerified), "true", StringComparison.InvariantCultureIgnoreCase);
                    user.SetPhoneNumber(phoneNumber, phoneNumberConfirmed);
                }

                await UserManager.UpdateAsync(user);

                if (IsLinkLogin)
                {
                    using (CurrentPrincipalAccessor.Change(await SignInManager.CreateUserPrincipalAsync(user)))
                    {
                        await IdentityLinkUserAppService.LinkAsync(new LinkUserInput
                        {
                            UserId = LinkUserId.Value,
                            TenantId = LinkTenantId,
                            Token = LinkToken
                        });
                    }
                }

                await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
                {
                    Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
                    Action = result.ToIdentitySecurityLogAction(),
                    UserName = user.UserName
                });

                return RedirectSafely(returnUrl, returnUrlHash);
            }
            return RedirectSafely(returnUrl, returnUrlHash);
        }
public override async Task<Microsoft.AspNetCore.Mvc.IActionResult> OnGetExternalLoginCallbackAsync(string returnUrl = "", string returnUrlHash = "", string remoteError = null)
{
    var loginInfo = await SignInManager.GetExternalLoginInfoAsync();

    if (loginInfo == null)
    {
        return RedirectToPage("./Login");
    }

    var result = await SignInManager.ExternalLoginSignInAsync(
        loginInfo.LoginProvider,
        loginInfo.ProviderKey,
        isPersistent: false,
        bypassTwoFactor: true
    );
    var claims = loginInfo.Principal.Claims;

    if (!result.Succeeded)
    {
        await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
        {
            Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
            Action = "Login" + result
        });
    }

    if (result.IsLockedOut)
    {
        throw new UserFriendlyException("Cannot proceed because user is locked out!");
    }

    if (result.IsNotAllowed)
    {
        throw new UserFriendlyException("Cannot proceed because user is not allowed!");
    }

    if (result.Succeeded)
    {
        var user = await UserManager.FindByLoginAsync(loginInfo.LoginProvider, loginInfo.ProviderKey);
        if (IsLinkLogin)
        {
            using (CurrentPrincipalAccessor.Change(await SignInManager.CreateUserPrincipalAsync(user)))
            {
                await IdentityLinkUserAppService.LinkAsync(new LinkUserInput
                {
                    UserId = LinkUserId.Value,
                    TenantId = LinkTenantId,
                    Token = LinkToken
                });
            }
        }

        await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
        {
            Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
            Action = result.ToIdentitySecurityLogAction(),
            UserName = user.UserName
        });

        return RedirectSafely(returnUrl, returnUrlHash);
    }
    return RedirectSafely(returnUrl, returnUrlHash);
}

Thanks. Was able to override the OnGetExternalLoginCallbackAsync. still can't get the personal info updated for already existing users though all the claims are being retrieved properly.

I don't have .Web Project in my solution. Where do I override OnGetExternalLoginCallbackAsync method?

ok Thanks. If I update say the phone number on Azure, I am not able to get the updated phone number into Personal Info.

I am signing in with new user. Also I have noted that if I update any information on Personal Info, it is not updating on to Azure side of things.

Showing 1 to 8 of 8 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06