From 9d88511fa584f0081f585d0062f49ed1b3af0c7d Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 30 Sep 2019 19:00:39 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- Controllers/AuthController.cs | 25 ++++++-- Controllers/QBridgeController.cs | 98 ++++++++++++++++---------------- Program.cs | 1 + Properties/launchSettings.json | 4 +- 5 files changed, 72 insertions(+), 58 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5300785..e35c856 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -36,7 +36,7 @@ //"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)", //https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#specifying-the-browsers-url "pattern": "^\\s*Now listening on:\\s+http://\\S+:([0-9]+)", - "uriFormat": "http://localhost:%s/qbridge/" + "uriFormat": "http://localhost:%s/start/" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/Controllers/AuthController.cs b/Controllers/AuthController.cs index 7894039..a627b48 100644 --- a/Controllers/AuthController.cs +++ b/Controllers/AuthController.cs @@ -10,14 +10,21 @@ using System.Net.Http.Formatting; namespace qbridge.Controllers { - [Route("[controller]")] + //[Route("[controller]")] + [Route("")] [ApiController] [Produces("application/json")] public class OAuthRedirectController : ControllerBase { public const string CLIENT_ID = "ABj70Wv5gDauFd9KgKFwuvpQjfzTwEgodEG8tnBbS8mSQhNrZJ"; public const string CLIENT_SECRET = "XUmJyvEcEuwQuyhARUAm0a8G3gzbEAeMiATCLyFZ"; - public const string REDIRECT_URI = "https://localhost:5001/OAuthRedirect"; + +#if (DEBUG) + public const string REDIRECT_URI = "https://localhost:5001/redirect"; +#else + public const string REDIRECT_URI = "https://qboauth.ayanova.com/redirect"; +#endif + public const string DISCOVERY_DOCUMENT_URL = "https://developer.api.intuit.com/.well-known/openid_sandbox_configuration"; //current 2019 fall disco doc urls @@ -67,7 +74,7 @@ namespace qbridge.Controllers - [HttpGet("Start/{qboid}")] + [HttpGet("start/{qboid}")] public async Task GetAsync([FromRoute]string qboid) { @@ -82,7 +89,7 @@ namespace qbridge.Controllers if (DiscoveryDoc == null) { return Content($"

Error - Unable to fetch Discovery document from QuickBooks Online

Cannot proceed"); - + } @@ -120,13 +127,19 @@ namespace qbridge.Controllers // Redirect endpoint //Step 4 here: https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/openid-connect - [HttpGet] + [HttpGet("redirect")] public async Task GetAsync([FromQuery]string state, [FromQuery]string code, [FromQuery]string realmId) { //NOTE: state is our own state provided in the initial auth redirect //code is authorization code used to then get the refresh and access token //realmId is the id of the actual company database to work with chosen by user on login + if (DiscoveryDoc == null) + { + return Content($"

Error - Unable to fetch Discovery document from QuickBooks Online

Cannot proceed with Revoke"); + } + + //We arrive here after the user has logged in and now we should have the authorization code that can now be used to fetch the actual tokens we need var TokenEndpoint = DiscoveryDoc["token_endpoint"].Value(); if (string.IsNullOrWhiteSpace(TokenEndpoint)) @@ -221,7 +234,7 @@ namespace qbridge.Controllers { DiscoveryDoc = null; } - return; + return; } diff --git a/Controllers/QBridgeController.cs b/Controllers/QBridgeController.cs index 4da661a..bad4af2 100644 --- a/Controllers/QBridgeController.cs +++ b/Controllers/QBridgeController.cs @@ -18,64 +18,64 @@ namespace qbridge.Controllers } - [HttpGet] - public ContentResult Index() - { - var errorBlock = string.Empty; + // [HttpGet] + // public ContentResult Index() + // { + // var errorBlock = string.Empty; - var resp = $@" - - - - AyaNova QBOI bridge authorization server - + // var resp = $@" + // + // + // + // AyaNova QBOI bridge authorization server + // - - + // + // -
- {errorBlock} -
-

QBOI Bridge

+ //
+ // {errorBlock} + //
+ //

QBOI Bridge

-
-
-
- - -
-
-
- - -
-
-
- -
-
-
+ //
+ //
+ //
+ // + // + //
+ //
+ //
+ // + // + //
+ //
+ //
+ // + //
+ //
+ //
-
-
- - "; + //
+ //
+ // + // "; - return new ContentResult - { - ContentType = "text/html", - StatusCode = 200, - Content = resp - }; + // return new ContentResult + // { + // ContentType = "text/html", + // StatusCode = 200, + // Content = resp + // }; - } + // } - [HttpPost] - public IActionResult Index([FromForm]string uname,[FromForm]string pwd) - { - return Content($"Uname: {uname}, Password: {pwd}"); - } + // [HttpPost] + // public IActionResult Index([FromForm]string uname,[FromForm]string pwd) + // { + // return Content($"Uname: {uname}, Password: {pwd}"); + // } // public class CBUserModel diff --git a/Program.cs b/Program.cs index 1d5508a..5c67800 100644 --- a/Program.cs +++ b/Program.cs @@ -19,6 +19,7 @@ namespace qbridge public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) + .UseUrls("http://*:3003") .UseStartup(); } } diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index 2ffddf7..4371f79 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -4,7 +4,7 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:57520", + "applicationUrl": "http://localhost:3003", "sslPort": 44391 } }, @@ -21,7 +21,7 @@ "commandName": "Project", "launchBrowser": true, "launchUrl": "api/values", - "applicationUrl": "https://localhost:5001;http://localhost:5000", + "applicationUrl": "https://localhost:3003;http://localhost:3003", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }