Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • K'Smart 2 posts 72 karma points
    Mar 15, 2023 @ 00:33
    K'Smart
    0

    Unable to convert user ID (google-oauth2|***)to int using InvariantCulture

    Hello,

    I am using auth0 as external identity provider and authenticate frontend members. After login, I put the logic in returnUri page like this.

    var result = await HttpContext.AuthenticateAsync(Auth0Constants.AuthenticationScheme);
    
            if (!result.Succeeded) throw new Exception("Missing external cookie");
    
            var email = result.Principal.FindFirstValue(ClaimTypes.Email)
                        ?? result.Principal.FindFirstValue("email")
                        ?? throw new Exception("Missing email claim");
    
            var user = await _memberManager.FindByEmailAsync(email);
            if (user == null)
            {
                _memberService.CreateMemberWithIdentity(email, email, email, Constants.Security.DefaultMemberTypeAlias);
    
                user = await _memberManager.FindByNameAsync(email);
                await _memberManager.AddToRolesAsync(user, new[] { "User" });
            }
    
            await HttpContext.SignOutAsync(Auth0Constants.AuthenticationScheme);
            await _memberSignInManager.SignInAsync(user, false);
    

    I thought the auth0 cookie has been clean up and umbraco user has been logined. But got the error of "Unable to convert user ID (google-oauth2|*)to int using InvariantCulture" when calling memberManager.GetCurrentMemberAsync. It seems the memberManager still hold the external login schema?

    Any ideas will be appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft