Пример #1
0
        //кортеж item1-основной токен item2-рефлеш
        public async static Task <Tuple <string, string> > Refresh(ApplicationDbContext db, string userId, string refreshToken)
        {
            string hashToken = AuthJWT.GetHashRefreshToken(refreshToken);// refreshToken.GetHashCode();
            var    user      = await db.Users.FirstOrDefaultAsync(x1 => x1.Id == userId && x1.RefreshTokenHash == hashToken);

            if (user == null)
            {
                return(null);
            }
            string token = AuthJWT.GenerateRefreshToken();
            await user.SetRefreshToken(db, token);

            return(new Tuple <string, string>(AuthJWT.GenerateMainToken(AuthJWT.GetIdentity(user)), token));
        }
Пример #2
0
        //кортеж item1-основной токен item2-рефлеш
        public async static Task <Tuple <string, string> > Refresh(ApplicationDbContext db, UserManager <ApplicationUser> userManager, string username, string password)
        {
            var user = await userManager.FindByNameAsync(username);

            if (user == null)
            {
                return(null);
            }

            var passwordOK = await userManager.CheckPasswordAsync(user, password);

            if (!passwordOK)
            {
                return(null);
            }

            string refToken = AuthJWT.GenerateRefreshToken();
            await user.SetRefreshToken(db, refToken);

            return(new Tuple <string, string>(AuthJWT.GenerateMainToken(AuthJWT.GetIdentity(user)), refToken));
        }
Пример #3
0
        public async static Task <ClaimsIdentity> GetIdentity(string username, string password, UserManager <ApplicationUser> userManager)
        {
            var user = await ApplicationUser.LoginGet(userManager, username, password);

            return(AuthJWT.GetIdentity(user));
        }