Ejemplo n.º 1
0
        public async Task <ClaimsPrincipal> GetCurrent()
        {
            var token = GetToken();

            if (string.IsNullOrWhiteSpace(token))
            {
                return(null);
            }

            var result = _claimsCache.Get(token);

            if (result != null)
            {
                return(result);
            }

            var session = await _clientSessionsClient.GetAsync(token);

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

            if (DateTime.UtcNow - session.LastAction > LykkeConstants.SessionLifetime)
            {
                await _clientSessionsClient.DeleteSessionIfExistsAsync(token);

                return(null);
            }

            if (DateTime.UtcNow - session.LastAction > LykkeConstants.SessionRefreshPeriod)
            {
                await _clientSessionsClient.RefreshSessionAsync(token);
            }

            result = new ClaimsPrincipal(LykkeIdentity.Create(session.ClientId));
            if (session.PartnerId != null)
            {
                (result.Identity as ClaimsIdentity)?.AddClaim(new Claim("PartnerId", session.PartnerId));
            }

            if (session.Pinned)
            {
                (result.Identity as ClaimsIdentity)?.AddClaim(new Claim("TokenType", "Pinned"));
            }

            _claimsCache.Set(token, result);
            return(result);
        }
Ejemplo n.º 2
0
        public async Task <ClaimsPrincipal> GetCurrent()
        {
            var token = GetToken();

            if (string.IsNullOrWhiteSpace(token))
            {
                return(null);
            }

            var result = _claimsCache.Get(token);

            if (result != null)
            {
                return(result);
            }

            var session = await _clientSessionsClient.GetAsync(token);

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

            result = new ClaimsPrincipal(LykkeIdentity.Create(session.ClientId));
            if (session.PartnerId != null)
            {
                (result.Identity as ClaimsIdentity)?.AddClaim(new Claim(LykkeConstants.PartnerId, session.PartnerId));
            }

            if (session.Pinned)
            {
                (result.Identity as ClaimsIdentity)?.AddClaim(new Claim("TokenType", "Pinned"));
            }

            (result.Identity as ClaimsIdentity)?.AddClaim(new Claim(LykkeConstants.SessionId, session.SessionToken));
            (result.Identity as ClaimsIdentity)?.AddClaim(new Claim(LykkeConstants.SessionConfirmed, session.IsSessionConfirmed.ToString()));

            _claimsCache.Set(token, result);
            return(result);
        }