From 5fea7abf83cb5517ed26e5a89c0cfd9b73411d3f Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 1 Oct 2019 22:57:50 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.QBOI/Util.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.QBOI/Util.cs b/source/Plugins/AyaNova.Plugin.QBOI/Util.cs index 9453757..dff5edd 100644 --- a/source/Plugins/AyaNova.Plugin.QBOI/Util.cs +++ b/source/Plugins/AyaNova.Plugin.QBOI/Util.cs @@ -339,13 +339,15 @@ namespace AyaNova.PlugIn.QBOI // } - public static UInt64 RandomUint64() + + //Note, always returns a positive number, it's plenty random + public static Int64 RandomInt64() { using (System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider()) { - var buffer = new byte[sizeof(UInt64)]; + var buffer = new byte[sizeof(Int64)]; rng.GetBytes(buffer); - return BitConverter.ToUInt64(buffer, 0); + return Math.Abs(BitConverter.ToInt64(buffer, 0)); } } @@ -368,15 +370,18 @@ namespace AyaNova.PlugIn.QBOI static public void StartAuthorization() { //used to tie this session to the auth key on our server for fetching later - QBOI2_SESSION_TOKEN = RandomSessionToken(); + QBOI2_SESSION_TOKEN = RandomInt64().ToString(); + //shell out to browser for user to login to QB + System.Diagnostics.Process.Start("https://qboauth.ayanova.com/start/" + QBOI2_SESSION_TOKEN); - + //LOOP over and over every 5 seconds checking repeatedly for the state token to get off the server or until user selects quit in some dialog that needs to be shown here + + //If user selects cancel then just exit qboi - System.Diagnostics.Process.Start("https://qboauth.ayanova.com/start/" + System.Uri.EscapeDataString(QBOI2_SESSION_TOKEN)); + //When token found at server under this session token id then fetch it and continue on from here - //here we need to loop checking for the data we need on qboauth site or quit if user selects quit so - //a special dialog is required here or something + //NOTE: this app will handle refreshing the token in-session as apparently that's possible from here, maybe should test that or could simply just refresh via our server Intuit.Ipp.OAuth2PlatformClient.OAuth2Client oac = new OAuth2Client(Q2_CLIENT_ID, Q2_CLIENT_SECRET, Q2_REDIRECT_URL, Q2_ENVIRONMENT);