コード例 #1
0
        public async Task<ClaimsPrincipal> GetPrincipalFromSessionCookieValue(string cookieValue)
        {
            _logger.LogDebug("Accessing session in redis");
            var db = _redisCache.GetConnection().GetDatabase();
            var session = await db.StringGetAsync($"{SessionPrefix}{cookieValue}");
            
            if (!session.HasValue)
            {
                _logger.LogWarning($"Authentication failed. No session found with ID {cookieValue}");
                return new ClaimsPrincipal();
            }

            var authSession = JsonSerializer.Deserialize<ServiceStackSession>(session.ToString(), JsonSerializerOptions);
            
            return _serviceStackSessionMapper.CreatePrincipalFromSession(authSession);
        }