Место общения программистов C#
-
Anonymous
Как управлять историей входов пользователей в контекст Owin (в ASP.NET WebAPI)
Сообщение
Anonymous »
Код: Выделить всё
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var userManager = context.OwinContext.GetUserManager();
ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
OAuthDefaults.AuthenticationType);
ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties properties = CreateProperties(user.UserName);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
user.Logins.Add(new IdentityUserLogin { UserId = user.Id, LoginProvider = "self",ProviderKey="" });
await userManager.UpdateAsync(user);
}
Это мой код готов. Теперь я хочу управлять историей входов пользователя, например LastLoginDate. Вот мой код готов.
Подробнее здесь:
https://stackoverflow.com/questions/395 ... net-webapi
1737128183
Anonymous
[code] public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var userManager = context.OwinContext.GetUserManager();
ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
OAuthDefaults.AuthenticationType);
ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties properties = CreateProperties(user.UserName);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
user.Logins.Add(new IdentityUserLogin { UserId = user.Id, LoginProvider = "self",ProviderKey="" });
await userManager.UpdateAsync(user);
}
[/code]
Это мой код готов. Теперь я хочу управлять историей входов пользователя, например LastLoginDate. Вот мой код готов.
Подробнее здесь: [url]https://stackoverflow.com/questions/39504695/how-to-manage-user-login-history-in-owin-context-in-asp-net-webapi[/url]