Ejemplo n.º 1
0
        public Task RenewAsync(string key, AuthenticationTicket ticket)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException(nameof(ticket));
            }

            using (SqlAuthSessionStoreContext store = new SqlAuthSessionStoreContext(_connectionString))
            {
                AuthSessionEntry entry = store.Entries.FirstOrDefault(a => a.Key == key);
                if (entry != null)
                {
                    entry.TicketString = _formatter.Protect(ticket);
                    entry.ValidUntil   = ticket.Properties.ExpiresUtc;
                }
                else
                {
                    store.Entries.Add(new AuthSessionEntry {
                        Key = key, TicketString = _formatter.Protect(ticket), ValidUntil = ticket.Properties.ExpiresUtc
                    });
                }

                store.SaveChanges();
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 2
0
        public Task RemoveAsync(string key)
        {
            using (SqlAuthSessionStoreContext store = new SqlAuthSessionStoreContext(_connectionString))
            {
                AuthSessionEntry entry = store.Entries.FirstOrDefault(a => a.Key == key);
                if (entry != null)
                {
                    store.Entries.Remove(entry);
                    store.SaveChanges();
                }
            }

            return(Task.FromResult(0));
        }
Ejemplo n.º 3
0
        public Task <AuthenticationTicket> RetrieveAsync(string key)
        {
            AuthenticationTicket ticket = null;

            using (SqlAuthSessionStoreContext store = new SqlAuthSessionStoreContext(_connectionString))
            {
                AuthSessionEntry entry = store.Entries.FirstOrDefault(a => a.Key == key);
                if (entry != null)
                {
                    ticket = _formatter.Unprotect(entry.TicketString);
                }

                return(Task.FromResult(ticket));
            }
        }
Ejemplo n.º 4
0
        public Task <string> StoreAsync(AuthenticationTicket ticket)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException(nameof(ticket));
            }

            string key = Guid.NewGuid().ToString();

            using (SqlAuthSessionStoreContext store = new SqlAuthSessionStoreContext(_connectionString))
            {
                store.Entries.Add(new AuthSessionEntry {
                    Key = key, TicketString = _formatter.Protect(ticket), ValidUntil = ticket.Properties.ExpiresUtc
                });
                store.SaveChanges();
            }

            return(Task.FromResult(key));
        }