I am learning google login feature in .net and implemented it in my sample test application which uses .Net 8 MVC and SQLite DB.
Everything works as expected except the await _userManager.AddLoginAsync(identityUser, extLoginInfo)
which always returns a “DuplicateUserName” error code, the error description says “Username [email protected] is already taken”.
I am pasting screenshot below of my two actions methods ExternalLogin
and ExternalLoginCallBack
. The problem happens in the second method, I have highlighted the error in QuickWatch window which you can see in the Screenshot 2.
Screenshot 1 ExternalLogin
Screenshot 2 ExternalLoginCallBack
Important Note. The screenshots show methods in controller. I have implemented signinmanager and usermanager in repository layer and calling the identity methods from controller using service layer. Therefore, in the screenshot, the method which has the breakpoint on line 103 calls the actual method i.e
_userManager.AddLoginAsync(identityUser, extLoginInfo)
Not sure why I get this error ? Tried other posts to find out the cause but nothing worked.
Will be very thankful to anyone who can help me ? Thank you in advance.
Scenario 1
I tried with existing users that I registered using my application registration page. These users are saved as expected in AspNetUsers Table. Now if I use the same user to login using google authentication screen, it does not create an entry in AspNetUserLogin table.
Scenario 2
I also tried with new gmail email id that is not registered in my AspNetUsers table, and used it to directly login through google authentication however, it also does not create an entry in AspNetUserLogin table. However this new user is added successfully in my AspNetUsers table.
In both the scenarios the error is same “DuplicateUserName”.
Abhishek Jadhav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.