Пример #1
0
        public object GetToken([FromQuery] SessionCodeQueryModel parameters)
        {
            var sessionHandler = AuthSessionStorage.GetHandler(parameters.SessionCode);

            if (sessionHandler == null)
            {
                throw new AuthenticationException("Session handler not found.");
            }
            else if (sessionHandler.UserUuid == null)
            {
                throw new AuthenticationException("Authentication not finished.");
            }
            else if (sessionHandler.IsExpired)
            {
                throw new AuthenticationException("Session handler has expired.");
            }

            try
            {
                var token = tokenRepository.CreateToken(sessionHandler.UserUuid.Value, new TimeSpan(TokenDurationDays, 0, 0, 0));
                return(TokenModel.Create(token));
            }
            finally
            {
                AuthSessionStorage.RemoveHandler(sessionHandler.Code);
            }
        }
Пример #2
0
        public object GetIsAuthenticated([FromQuery] SessionCodeQueryModel parameters)
        {
            var handler = AuthSessionStorage.GetHandler(parameters.SessionCode);

            if (handler == null)
            {
                throw new AuthenticationException("Session handler not found.");
            }

            return(new OperationResultModel()
            {
                Result = handler.UserUuid != null
            });
        }