var user = await UserManager.FindByNameAsync("username"); var result = await UserManager.AddLoginAsync(user.Id, new UserLoginInfo("providerName", "providerKey")); if (result.Succeeded) { // Login added successfully }
var user = await UserManager.FindByIdAsync(userId); if (user != null) { var login = new UserLoginInfo(provider, providerKey); var result = await UserManager.AddLoginAsync(user.Id, login); if (result.Succeeded) { // Login added successfully } }This example finds a user by their Id and adds a login with provider name and provider key to their account. In both examples, UserManager is an instance of UserStore. These methods demonstrate how to use the AddLoginAsync method to add a login to a user account.