public string TrueLayerAuthentication()
        {
            try
            {
                var form = Request.Form;
                form.TryGetValue("code", out StringValues codeStrV);
                form.TryGetValue("state", out StringValues stateStrV);
                form.TryGetValue("error", out StringValues errors);

                //Validate Request data
                if (string.IsNullOrEmpty(codeStrV) || codeStrV.Count != 1 || string.IsNullOrEmpty(stateStrV) || stateStrV.Count != 1 || !string.IsNullOrEmpty(errors))
                {
                    Response.StatusCode = StatusCodes.Status422UnprocessableEntity;
                    return("Something went wrong");
                }

                string sessionID = stateStrV[0];
                string code      = codeStrV[0];

                string scheme = Request.Scheme;
                if (!string.IsNullOrEmpty(Request.Headers["X-Forwarded-Proto"]))
                {
                    scheme = Request.Headers["X-Forwarded-Proto"];
                }

                var location = new Uri($"{scheme}://{Request.Host}{Request.Path}{Request.QueryString}");

                var clientId = _jwtMiddleware.GetClientIdFromToken(sessionID);
                if (clientId == null)
                {
                    return("Invalid User");
                }


                TrueLayerAPI trueLayerAPI = new TrueLayerAPI(_appSettings.MongoDB_ConnectionString, _appSettings.TrueLayer_ClientID, _appSettings.TrueLayer_ClientSecret, _appSettings.TrueLayer_Mode);
                return(trueLayerAPI.RegisterNewClient(code, clientId, location.AbsoluteUri) ? "Datafeed has been Added. \nPlease Refresh finance manager" : "Something went wrong");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return("Something went wrong. The error has been logged in the console");
            }
        }
 public CreditCardTransactionLoader(AuthService authService, TrueLayerAPI trueLayerApi, LiteDBDatastore dataStore)
     : base(authService, trueLayerApi, dataStore)
 {
 }
Ejemplo n.º 3
0
 public AuthService(LiteDBDatastore dataStore, TrueLayerAuth trueLayerAuth, TrueLayerAPI trueLayerApi)
 {
     _dataStore     = dataStore;
     _trueLayerAuth = trueLayerAuth;
     _trueLayerApi  = trueLayerApi;
 }
Ejemplo n.º 4
0
        public override void Execute(Task task)
        {
            Task = task;
            var args = Task.Data;

            _datafeedDataService    = new FinanceAPIMongoDataService.DataService.DatafeedDataService(Settings.MongoDB_ConnectionString);
            _accountDataService     = new FinanceAPIMongoDataService.DataService.AccountDataService(Settings.MongoDB_ConnectionString);
            _transactionDataService = new FinanceAPIMongoDataService.DataService.TransactionsDataService(Settings.MongoDB_ConnectionString);

            if (string.IsNullOrEmpty(args["AccountID"].ToString()))
            {
                base.Execute(Task);
                return;
            }

            string accountID = args["AccountID"].ToString();

            if (!_accountDataService.GetAccounts(Task.ClientID).Any(a => a.ID == accountID))
            {
                base.Execute(Task);
                return;
            }

            List <ExternalAccount> externalAccounts = _datafeedDataService.GetExternalAccounts(Task.ClientID, accountID);
            Account      account     = _accountDataService.GetAccountById(accountID, Task.ClientID);
            IDatafeedAPI datafeedApi = new TrueLayerAPI(Settings.MongoDB_ConnectionString, Settings.TrueLayer_ClientID, Settings.TrueLayer_ClientSecret, Settings.TrueLayer_Mode);

            if (account == null || externalAccounts.Count == 0)
            {
                base.Execute(Task);
                return;
            }

            AccountSettings accountSettings = _accountDataService.GetAccountSettings(accountID);

            decimal totalAccountBalance          = 0;
            decimal totalAvailableAccountBalance = 0;

            foreach (var externalAccount in externalAccounts)
            {
                totalAccountBalance          += ProcessExternalAccount(externalAccount, datafeedApi, account, out decimal availableBalance);
                totalAvailableAccountBalance += availableBalance;
            }

            // Reload account to get new balance
            account = _accountDataService.GetAccountById(accountID, Task.ClientID);

            if (accountSettings != null && accountSettings.GenerateAdjustments)
            {
                BalanceAccount(account, totalAccountBalance);
            }

            // Enqueue task to calculate logos on new transactions
            Task logoTask = new Task($"Logo Calculator [{account.AccountName}]", Task.ClientID, TaskType.LogoCalculator, DateTime.Now);

            logoTask.Data = new Dictionary <string, object> {
                { "ClientID", Task.ClientID }, { "AccountID", accountID }
            };

            // Set Account Last Refreshed Date
            _accountDataService.UpdateLastRefreshedDate(accountID, DateTime.Now);

            BackgroundJob.Enqueue <LogoCalculatorTask>(t => t.Execute(logoTask));
            base.Execute(Task);
        }
Ejemplo n.º 5
0
 public AccountLoader(AuthService authService, TrueLayerAPI trueLayerApi, LiteDBDatastore dataStore)
     : base(authService, trueLayerApi, dataStore)
 {
 }
Ejemplo n.º 6
0
 public Loader(AuthService authService, TrueLayerAPI trueLayerApi, LiteDBDatastore dataStore)
 {
     _authService  = authService;
     _trueLayerApi = trueLayerApi;
     _dataStore    = dataStore;
 }