AccessToken IAuthenticationService.ConfirmToken(HttpRequest httpRequest, string appInstanceId, string accessToken, string cNonce)
        {
            var appInstance = _appInstanceStorage.Get(appInstanceId);

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

            // TODO: Validate client host from HttpContext
            // httpRequest.HttpContext.GetFeature<IHttpConnectionFeature>().RemoteIpAddress;

            // TODO: Validate timestamp/expired
            var accessTokenFound = _accessTokenStorage.All.SingleOrDefault(where =>
                                                                           where.AppInstance.Id == appInstance.Id && where.StringId == accessToken);

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

            // Regenerate Token
            var sealedToken = accessTokenFound.Seal(cNonce);

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

            _logger.LogInformation("SealedToken: {0}, NonceOrder: {1}", sealedToken.StringId, sealedToken.AppNonceOrder.Template);

            _accessTokenStorage.Remove(accessTokenFound);

            return(_accessTokenStorage.Add(sealedToken));
        }
        public TransactionResponse Add(TransactionRequest transactionRequest)
        {
            var model = _mapper.Map <TransactionEntity>(transactionRequest);

            _dataStorage.Add(model);
            return(_mapper.Map <TransactionResponse>(model));
        }
        public void Register([NotNull] string navigationKey, [NotNull] Func <object> getViewModel, [NotNull] Func <object> getView)
        {
            if (navigationKey == null)
            {
                throw new ArgumentNullException(nameof(navigationKey));
            }

            if (getViewModel == null)
            {
                throw new ArgumentNullException(nameof(getViewModel));
            }

            if (getView == null)
            {
                throw new ArgumentNullException(nameof(getView));
            }

            var isKeyAlreadyRegistered = _dataStorage.IsExist(navigationKey);

            if (isKeyAlreadyRegistered)
            {
                throw new InvalidOperationException(ExceptionMessages.CanNotRegisterKeyTwice);
            }

            var navigationData = new NavigationData(getViewModel, getView);

            _dataStorage.Add(navigationKey, navigationData);
        }
 public void AddPerson(Person person, ulong id)
 => _dataStorage.Add(TableName, person, id);