Ejemplo n.º 1
0
        protected SessionEntity SessionFromContext(ServerCallContext context)
        {
            var sessionId = context.GetToken();

            if (string.IsNullOrEmpty(sessionId))
            {
                return(null);
            }

            var session = _sessionService.GetSessionByOriginToken(sessionId);

            return(session);
        }
Ejemplo n.º 2
0
        public override async Task <TResponse> UnaryServerHandler <TRequest, TResponse>(TRequest request,
                                                                                        ServerCallContext context,
                                                                                        UnaryServerMethod <TRequest, TResponse> continuation)
        {
            if (!IsAuthRequired(context))
            {
                return(await base.UnaryServerHandler(request, context, continuation));
            }

            var sessionId = context.GetToken();

            if (sessionId == null)
            {
                context.Status = new Status(StatusCode.Unauthenticated, "InvalidToken");
                return(Activator.CreateInstance <TResponse>());
            }

            var session = _sessionService.GetSession(sessionId);

            if (session == null)
            {
                context.Status = new Status(StatusCode.Unauthenticated, "SessionNotFound");
                return(Activator.CreateInstance <TResponse>());
            }

            if (!session.Verified)
            {
                context.Status = new Status(StatusCode.Unauthenticated, "SessionNotVerified");
                return(Activator.CreateInstance <TResponse>());
            }

            if (DateTime.UtcNow > session.ExpirationDate)
            {
                context.Status = new Status(StatusCode.Unauthenticated, "SessionExpired");
                return(Activator.CreateInstance <TResponse>());
            }

            context.UserState.Add(UserStateProperties.ClientId, session.ClientId);
            context.UserState.Add(UserStateProperties.PartnerId, session.PartnerId);
            context.UserState.Add(UserStateProperties.Token, session.Token);
            context.UserState.Add(UserStateProperties.SessionId, session.Id);
            context.UserState.Add(UserStateProperties.LykkeSessionId, session.LykkeSessionId);

            return(await base.UnaryServerHandler(request, context, continuation));
        }
Ejemplo n.º 3
0
        public override async Task <EmptyResponse> Logout(Empty request, ServerCallContext context)
        {
            var result = new EmptyResponse();

            string sessionId = context.GetToken();

            var session = _sessionService.GetSession(sessionId);

            if (session == null)
            {
                result.Error = new ErrorResponseBody
                {
                    Code    = ErrorCode.Unauthorized,
                    Message = ErrorMessages.InvalidToken
                };

                return(result);
            }

            await _sessionService.LogoutAsync(session);

            return(result);
        }