2014-10-14 2 views
2

액세스 토큰을 얻고 요청의 날짜/시간 및 IP를 저장하려는 각 성공 또는 실패한 시도를 기록하는 가장 좋은 방법을 간략히 설명하는 문서를 검색했지만 찾지 못했습니다. 응용 프로그램 내에서 어디에서이 작업을 수행 할 수 있습니까?ASP.NET 웹 API 로그인 내역 구현

답변

1

확인. 이 질문에 대답하는 데 관심이 없다는 것은 이상한 일입니다.

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); 
    } 

내가에 코멘트를 넣어 :

어떤 시험/오류 및 디버그 추적 후, 나는 전형적인 ASP.NET 웹 API 템플릿의 Providers 폴더에있는 ApplicationOAuthProvider는 다음이 포함되어 있는지 발견 로깅을 구현할 수있는 위치를 보여주는 코드. 도움이되기를 바랍니다.