I m watching strange behavior of ASP.NET Identity. It has standard feature for locking users. I want to lock user from server code explicitly to prevent his access to the site and WEB API. The code is trivial and works well:
var userStore = new UserStore<User>(db);
var userManager = new UserManager<User>(userStore);
var result = userManager.SetLockoutEnabled(user.Id, true);
result = userManager.SetLockoutEndDate(user.Id, DateTimeOffset.MaxValue);
After executing this snippet, I can see that user record in database updated properly. When I try to log on my site with credentials of this user, I receive correct message that user is locked out.
Next, I m trying to log on the same user through WEB API using a simple C# console client and get access token.
Dictionary<string, string> request = new Dictionary<string, string>();
request.Add("grant_type", "password");
request.Add("username", user);
request.Add("password", pass);
HttpContent con = new FormUrlEncodedContent(request);
TokenModel tokenModel;
using (HttpClient client = new HttpClient { BaseAddress = new Uri(url + "/Token") })
{
HttpResponseMessage responseMessage = await client.PostAsync("", con);
string responseContent = await responseMessage.Content.ReadAsStringAsync();
tokenModel = JsonConvert.DeserializeObject<TokenModel>(responseContent);
}
To my surprise, logon succeeds and returns valid access token for this locked user! How is it possible? Am I missing something? Is it a bug in identity implementation?
I m using Visual Studio 2013 and latest ASP.NET Identity 2.2.1.