This commit is contained in:
2019-09-30 19:00:39 +00:00
parent 59c710dd14
commit 9d88511fa5
5 changed files with 72 additions and 58 deletions

2
.vscode/launch.json vendored
View File

@@ -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"

View File

@@ -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<IActionResult> GetAsync([FromRoute]string qboid)
{
@@ -82,7 +89,7 @@ namespace qbridge.Controllers
if (DiscoveryDoc == null)
{
return Content($"<h1>Error - Unable to fetch Discovery document from QuickBooks Online</h1>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<IActionResult> 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($"<h1>Error - Unable to fetch Discovery document from QuickBooks Online</h1>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<string>();
if (string.IsNullOrWhiteSpace(TokenEndpoint))
@@ -221,7 +234,7 @@ namespace qbridge.Controllers
{
DiscoveryDoc = null;
}
return;
return;
}

View File

@@ -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 = $@"<html lang=""en"">
<head>
<meta charset=""utf-8"">
<meta name=""viewport"" content=""width=device-width, initial-scale=1, shrink-to-fit=no"">
<title>AyaNova QBOI bridge authorization server</title>
<script src=/jquery-1.9.1.js></script>
// var resp = $@"<html lang=""en"">
// <head>
// <meta charset=""utf-8"">
// <meta name=""viewport"" content=""width=device-width, initial-scale=1, shrink-to-fit=no"">
// <title>AyaNova QBOI bridge authorization server</title>
// <script src=/jquery-1.9.1.js></script>
</head>
<body >
// </head>
// <body >
<div style=""text-align: center;"">
{errorBlock}
<div style=""display: inline-block;text-align:left;"">
<h1>QBOI Bridge</h1>
// <div style=""text-align: center;"">
// {errorBlock}
// <div style=""display: inline-block;text-align:left;"">
// <h1>QBOI Bridge</h1>
<form action=""/QBridge"" method=""post"">
<div class=""container"">
<div>
<label for=""uname""><b>User name</b></label>
<input type=""text"" placeholder=""Enter Username"" id=""uname"" name=""uname"" required>
</div>
<br/>
<div>
<label for=""pwd""><b>Password</b></label>
<input type=""password"" placeholder=""Enter Password"" id=""pwd"" name=""pwd"" required>
</div>
<br/>
<div>
<button type=""submit"">Login</button>
</div>
</div>
</form>
// <form action=""/QBridge"" method=""post"">
// <div class=""container"">
// <div>
// <label for=""uname""><b>User name</b></label>
// <input type=""text"" placeholder=""Enter Username"" id=""uname"" name=""uname"" required>
// </div>
// <br/>
// <div>
// <label for=""pwd""><b>Password</b></label>
// <input type=""password"" placeholder=""Enter Password"" id=""pwd"" name=""pwd"" required>
// </div>
// <br/>
// <div>
// <button type=""submit"">Login</button>
// </div>
// </div>
// </form>
</div>
</div>
</body>
</html>";
// </div>
// </div>
// </body>
// </html>";
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

View File

@@ -19,6 +19,7 @@ namespace qbridge
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:3003")
.UseStartup<Startup>();
}
}

View File

@@ -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"
}