public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();

            ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);
            //SessionHelper.UserSessionID = user.Id;
            AspNetUsersController aspUserCon = new AspNetUsersController();
            var sessionUser = aspUserCon.GetUser(user.Id);
            //SessionHelper.UserSessionID = user.UserName;
            SessionHelper.LoggedInUser<AspNetUser>(sessionUser, user.UserName);
            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 void OnActionExecuting(HttpActionContext actionContext)
 {
     base.OnActionExecuting(actionContext);
     if (HttpContext.Current != null && HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
     {
         if (SessionHelper.LoggedInUser<AspNetUser>(HttpContext.Current.User.Identity.Name) == null)
         {
             //SessionHelper.UserSessionID = user.Id;
             AspNetUsersController aspUserCon = new AspNetUsersController();
             var sessionUser = aspUserCon.GetUser(HttpContext.Current.User.Identity.Name);
             //SessionHelper.UserSessionID = user.UserName;
             SessionHelper.LoggedInUser<AspNetUser>(sessionUser, sessionUser.UserName);
         }
     }
 }