コード例 #1
0
        // Describe User / Session

        public async Task <SessionDetails> GetSessionDetailsAsync(ClaimsPrincipal principal)
        {
            var sessionId = GetSessionId(principal);

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

            var session = await _persistence.UserSessions.GetAsync(UserSessionId.FromString(sessionId));

            var user = await _persistence.Users.GetAsync(session.UserId);

            return(new SessionDetails()
            {
                Id = session.Id,
                CreationTime = session.CreationTime,
                LogoutTime = session.LogoutTime,
                User = new UserDetails()
                {
                    Id = user.Id,
                    Username = user.Username,
                    EmailAddress = user.EmailAddress
                }
            });
        }
コード例 #2
0
        // Logout

        public async Task LogoutAsync()
        {
            await _context.HttpContext.SignOutAsync();

            var sessionId = GetSessionId(_context.HttpContext.User);

            if (sessionId != null)
            {
                await _persistence.UserSessions.LogoutAsync(UserSessionId.FromString(sessionId), DateTime.UtcNow);
            }
        }
コード例 #3
0
        // Validate Login

        public async Task <bool> ValidateLoginAsync(ClaimsPrincipal principal)
        {
            var sessionId = GetSessionId(principal);

            if (sessionId == null)
            {
                return(false);
            }

            var session = await _persistence.UserSessions.GetAsync(UserSessionId.FromString(sessionId));

            if (session.LogoutTime.HasValue)
            {
                return(false);
            }

            // add in options like updating it with a last seen time, expiration, etc
            // add in options like IP Address roaming check

            return(true);
        }