Пример #1
0
        private async Task <RefreshToken> GenerateRefreshToken(User objUser)
        {
            using (var rngCryptoServiceProvider = new RNGCryptoServiceProvider())
            {
                var randomBytes = new byte[64];
                rngCryptoServiceProvider.GetBytes(randomBytes);
                string refreshToken = Convert.ToBase64String(randomBytes);

                RefreshToken objRefreshToken = await _context.RefreshToken.FirstOrDefaultAsync(x => x.UserId == objUser.Id);

                if (objRefreshToken == null)
                {
                    objRefreshToken = new RefreshToken
                    {
                        Token   = refreshToken,
                        Expires = DateTime.Now.AddDays(7),
                        UserId  = objUser.Id
                    };
                    await _context.RefreshToken.AddAsync(objRefreshToken);
                }
                else
                {
                    objRefreshToken.Token   = refreshToken;
                    objRefreshToken.Expires = DateTime.Now.AddDays(7);
                }
                await _context.SaveChangesAsync();

                return(objRefreshToken);
            }
        }
Пример #2
0
 public async System.Threading.Tasks.Task Create(Profile obj)
 {
     _context.Profiles.Add(obj);
     await _context.SaveChangesAsync();
 }
 public async Task <int> Delete(RefreshToken objRefreshToken)
 {
     _context.RefreshToken.Remove(objRefreshToken);
     return(await _context.SaveChangesAsync());
 }