I want to authenticate a user with only user name and no password. My application does not have any user management data and I just want to create Identity with user details so that I can use it in the application.
I tried to copy the SingInAsync method to put this up
private async Task InitializeUser()
{
var user = new ApplicationUser();
user.Id = "abcd";
user.UserName = "abcd";
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity);
}
But it tells me and error - that user ID cannot be found. Is there someway I can just authenticate the user by username and assign the Identity with some details??
With no users just forget about the UserManager and create the
ClaimsIdentity
yourself.You probably want to tweak this a bit to make it cleaner.