Пример #1
0
        //public override Task<ClaimsIdentity> CreateUserIdentityAsync(AutoCareUser user)
        //{
        //    //var identity = new ClaimsIdentity("JWT");
        //    var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
        //    var appUserManager = (ApplicationUserManager)UserManager;
        //    identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));
        //    identity.AddClaim(new Claim(ClaimTypes.Role, "user"));
        //    return Task.FromResult(identity);
        //    //return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
        //}

        public override async Task <SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout)
        {
            var token = await _jwtTokenHelper.GetTokenAsync(userName, password);

            if (token == null)
            {
                return(SignInStatus.Failure);
            }

            int tokenLifeSpanInMinutes = AppSettingConfiguration.Instance.DefaultTokenExpirationTimeInMinutes;

            if (isPersistent)
            {
                tokenLifeSpanInMinutes = AppSettingConfiguration.Instance.RememberMeTokenExpirationTimeInMinutes;
            }

            var claimsIdentity = await _jwtTokenHelper.GetClaimsAsync(token, DefaultAuthenticationTypes.ApplicationCookie, tokenLifeSpanInMinutes);

            var context = HttpContext.Current.Request.GetOwinContext();
            var authenticationManager = context.Authentication;

            authenticationManager.SignIn(claimsIdentity);

            return(SignInStatus.Success);
        }