コード例 #1
0
        public IndexModule()
        {
            Get["/{id?}", true] = async (parameters, ct) => {
                FigoSession figoSession = null;
                models.IndexModel model = null;

                // checkout whether we are logged in already
                if(Request.Session["figo_token"] == null) {
                    return Response.AsRedirect(_figoConnection.GetLoginUrl(null, "qweqwe"));
                } else {
                    figoSession = new FigoSession { AccessToken = Request.Session["figo_token"].ToString() };
                }

                if(parameters.ContainsKey("id"))
                    model = new models.IndexModel {
                        User = await figoSession.GetUser(),

                        Accounts = await figoSession.GetAccounts(),
                        CurrentAccount = await figoSession.GetAccount(parameters.id),
                        CurrentAccountBalance = await figoSession.GetAccountBalance(parameters.id),

                        Transactions = await figoSession.GetTransactions(parameters.id),
                    };
                else
                    model = new models.IndexModel {
                        User = await figoSession.GetUser(),

                        Accounts = await figoSession.GetAccounts(),
                        CurrentAccount = null,
                        CurrentAccountBalance = null,

                        Transactions = await figoSession.GetTransactions(),
                    };
                return View["index", model];
            };

            Get["/logout", true] = async (parameters, ct) => {
                if (Request.Session["figo_token"] != null) {
                    await _figoConnection.RevokeToken(Request.Session["figo_token"].ToString());
                }

                Request.Session.DeleteAll();
                return Response.AsRedirect("/");
            };

            Get["/callback", true] = async (parameters, ct) => {
                if (Request.Query["code"] != null) {
                    TokenResponse tokenResponse = await _figoConnection.ConvertAuthenticationCode(Request.Query["code"]);
                    Request.Session["figo_token"] = tokenResponse.AccessToken;
                }
                return Response.AsRedirect("/");
            };
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Leondra/net-figo
        static void Main(string[] args)
        {
            var validCertificates = new string[]
            {
                "38AE4A326F16EA1581338BB0D8E4A635E727F107",
                "DBE2E9158FC9903084FE36CAA61138D85A205D93"
            };
            FigoSession session = new FigoSession
            {
                AccessToken = "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ",
                // the same as default one here, but can be modified for testing purposes
                ApiEndpoint         = "https://api.figo.me",
                OnRequestInitialize = (request) =>
                {
                    // figo.net is portable, not all of the platforms have a support for ServerCertificateValidationCallback
                    // that's why check certificate on the client side
                    request.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => {
                        X509Certificate x509Certificate = cert;
                        return(validCertificates.Contains(x509Certificate.GetCertHashString()));
                    };
                }
            };
            // print out a list of accounts including its balance
            var task_accounts = session.GetAccounts();

            WaitTask(task_accounts);
            foreach (FigoAccount account in task_accounts.Result)
            {
                Console.WriteLine(account.Name);

                var task_balance = session.GetAccountBalance(account);
                WaitTask(task_balance);
                Console.WriteLine(task_balance.Result.Balance);
            }

            // print out the list of all transactions on a specific account
            var task_transactions = session.GetTransactions("A1.2");

            WaitTask(task_transactions);
            foreach (FigoTransaction transaction in task_transactions.Result)
            {
                Console.WriteLine(transaction.Purpose);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: SvenLauterbach/net-figo
        static void Main(string[] args)
        {
            FigoSession session = new FigoSession { AccessToken = "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ" };

            // print out a list of accounts including its balance
            var task_accounts = session.GetAccounts();
            task_accounts.Wait();
            foreach(FigoAccount account in task_accounts.Result) {
                Console.WriteLine(account.Name);

                var task_balance = session.GetAccountBalance(account);
                task_balance.Wait();
                Console.WriteLine(task_balance.Result.Balance);
            }

            // print out the list of all transactions on a specific account
            var task_transactions = session.GetTransactions("A1.2");
            task_transactions.Wait();
            foreach(FigoTransaction transaction in task_transactions.Result) {
                Console.WriteLine(transaction.Purpose);
            }
        }
コード例 #4
0
 public void SetUp()
 {
     sut = new FigoSession { AccessToken = "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ" };
 }
コード例 #5
0
 public void SetUp()
 {
     sut = new FigoSession {
         AccessToken = "ASHWLIkouP2O6_bgA2wWReRhletgWKHYjLqDaqb0LFfamim9RjexTo22ujRIP_cjLiRiSyQXyt2kM1eXU2XLFZQ0Hro15HikJQT_eNeT_9XQ"
     };
 }
コード例 #6
0
        public IndexModule()
        {
            Get["/{id?}", true] = async(parameters, ct) => {
                FigoSession       figoSession = null;
                models.IndexModel model       = null;

                // checkout whether we are logged in already
                if (Request.Session["figo_token"] == null)
                {
                    return(Response.AsRedirect(_figoConnection.GetLoginUrl(null, "qweqwe")));
                }
                else
                {
                    figoSession = new FigoSession {
                        AccessToken = Request.Session["figo_token"].ToString()
                    };
                }

                if (parameters.ContainsKey("id"))
                {
                    model = new models.IndexModel {
                        User = await figoSession.GetUser(),

                        Accounts              = await figoSession.GetAccounts(),
                        CurrentAccount        = await figoSession.GetAccount(parameters.id),
                        CurrentAccountBalance = await figoSession.GetAccountBalance(parameters.id),

                        Transactions = await figoSession.GetTransactions(parameters.id),
                    }
                }
                ;
                else
                {
                    model = new models.IndexModel {
                        User = await figoSession.GetUser(),

                        Accounts              = await figoSession.GetAccounts(),
                        CurrentAccount        = null,
                        CurrentAccountBalance = null,

                        Transactions = await figoSession.GetTransactions(),
                    }
                };
                return(View["index", model]);
            };

            Get["/logout", true] = async(parameters, ct) => {
                if (Request.Session["figo_token"] != null)
                {
                    await _figoConnection.RevokeToken(Request.Session["figo_token"].ToString());
                }

                Request.Session.DeleteAll();
                return(Response.AsRedirect("/"));
            };

            Get["/callback", true] = async(parameters, ct) => {
                if (Request.Query["code"] != null)
                {
                    TokenResponse tokenResponse = await _figoConnection.ConvertAuthenticationCode(Request.Query["code"]);

                    Request.Session["figo_token"] = tokenResponse.AccessToken;
                }
                return(Response.AsRedirect("/"));
            };
        }
    }