コード例 #1
0
        public override async Task CreateAsync(AuthenticationTokenCreateContext context)
        {
            context.Ticket.Properties.AllowRefresh = true;

            var refreshTokenId = Guid.NewGuid().ToString("n");

            using (PracaDorywczaDbContext db = new PracaDorywczaDbContext())
            {
                var token = new RefreshToken()
                {
                    Id         = GetHash(refreshTokenId),
                    UserName   = context.Ticket.Identity.Name,
                    IssuedUtc  = DateTime.UtcNow,
                    ExpiresUtc = DateTime.UtcNow.AddMinutes(10)
                };


                context.Ticket.Properties.IssuedUtc  = DateTimeOffset.Now;
                context.Ticket.Properties.ExpiresUtc = DateTimeOffset.Now.AddMinutes(10);

                token.ProtectedTicket = context.SerializeTicket();

                db.RefreshToken.Add(token);

                var result = await db.SaveChangesAsync() > 0;

                if (result)
                {
                    context.SetToken(refreshTokenId);
                }
            }
        }
コード例 #2
0
        public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            string hashedTokenId = GetHash(context.Token);

            using (PracaDorywczaDbContext db = new PracaDorywczaDbContext())
            {
                var refreshToken = await db.RefreshToken.FindAsync(hashedTokenId);

                if (refreshToken != null)
                {
                    context.DeserializeTicket(refreshToken.ProtectedTicket);
                    db.RefreshToken.Remove(refreshToken);
                    var result = await db.SaveChangesAsync() > 0;
                }
            }
        }
コード例 #3
0
ファイル: AuthRepository.cs プロジェクト: kamaz08/base
 public AuthRepository()
 {
     _context     = new PracaDorywczaDbContext();
     _userManager = new UserManager <AppUser>(new UserStore <AppUser>(_context));
 }