Login ASP.NET Web API登录历史记录的实现

Login ASP.NET Web API登录历史记录的实现,login,asp.net-web-api,oauth-2.0,Login,Asp.net Web Api,Oauth 2.0,我已经搜索过了,但没有找到任何文档,概述了记录每次成功或失败的尝试以获取访问令牌并存储请求的日期/时间和IP的最佳方法。在应用程序中,在哪里可以执行此操作?确定。奇怪的是,没有人对回答这个问题感兴趣 经过一些尝试/错误和调试跟踪,我发现位于典型ASP.NET Web API模板中的Providers文件夹中的ApplicationAuthProvider包含以下内容: public override async Task GrantResourceOwnerCredentials(OAu

我已经搜索过了,但没有找到任何文档,概述了记录每次成功或失败的尝试以获取访问令牌并存储请求的日期/时间和IP的最佳方法。在应用程序中,在哪里可以执行此操作?

确定。奇怪的是,没有人对回答这个问题感兴趣

经过一些尝试/错误和调试跟踪,我发现位于典型ASP.NET Web API模板中的
Providers
文件夹中的
ApplicationAuthProvider
包含以下内容:

    public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
    {
        var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();

        ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);

        //log the authentication attempt here

        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);
    }
public override异步任务GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext)
{
var userManager=context.OwinContext.GetUserManager();
ApplicationUser user=await userManager.FindAsync(context.UserName,context.Password);
//在此处记录身份验证尝试
if(user==null)
{
SetError(“无效的授权”,“用户名或密码不正确”);
返回;
}
ClaimsIdentity oAuthIdentity=等待用户.GenerateUserIdentityAsync(userManager,
OAuthDefaults.AuthenticationType);
ClaimSideEntity cookiesIdentity=等待用户.GenerateUserIdentity异步(userManager,
CookieAuthenticationDefaults.AuthenticationType);
AuthenticationProperties=CreateProperties(user.UserName);
AuthenticationTicket=新的AuthenticationTicket(OAuthidentitity,属性);
上下文。已验证(票证);
context.Request.context.Authentication.sign(cookiesIdentity);
}
我在代码中添加了一条注释,以显示可以在何处实现日志记录。我希望这有帮助