This commit is contained in:
@@ -3,7 +3,8 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace qbridge.Controllers
|
namespace qbridge.Controllers
|
||||||
{
|
{
|
||||||
@@ -12,10 +13,20 @@ namespace qbridge.Controllers
|
|||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
public class OAuthRedirectController : ControllerBase
|
public class OAuthRedirectController : ControllerBase
|
||||||
{
|
{
|
||||||
|
//used for discovery document
|
||||||
|
//https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.0
|
||||||
|
private readonly IHttpClientFactory _clientFactory;
|
||||||
|
public JObject DiscoveryDoc { get; private set; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
Discovery document
|
||||||
|
https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/openid-connect#discovery-document
|
||||||
|
Endpoints:
|
||||||
|
https://developer.api.intuit.com/.well-known/openid_sandbox_configuration
|
||||||
|
https://developer.api.intuit.com/.well-known/openid_configuration
|
||||||
|
|
||||||
QB Online developer account login creds for sandbox:
|
QB Online developer account login creds for sandbox:
|
||||||
|
|
||||||
login: support@ayanova.com
|
login: support@ayanova.com
|
||||||
@@ -38,9 +49,9 @@ namespace qbridge.Controllers
|
|||||||
sandbox company_us_1
|
sandbox company_us_1
|
||||||
sandbox-quickbooks.api.intuit.com
|
sandbox-quickbooks.api.intuit.com
|
||||||
*/
|
*/
|
||||||
public OAuthRedirectController()
|
public OAuthRedirectController(IHttpClientFactory clientFactory)
|
||||||
{
|
{
|
||||||
|
_clientFactory = clientFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect endpoint
|
// Redirect endpoint
|
||||||
@@ -53,8 +64,9 @@ namespace qbridge.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("Start")]
|
[HttpGet("Start")]
|
||||||
public IActionResult Get()
|
public async Task<IActionResult> GetAsync()
|
||||||
{
|
{
|
||||||
|
await GetQBDiscoveryDocument();
|
||||||
string url = string.Empty;
|
string url = string.Empty;
|
||||||
var queryParams = new Dictionary<string, string>()
|
var queryParams = new Dictionary<string, string>()
|
||||||
{
|
{
|
||||||
@@ -66,7 +78,7 @@ namespace qbridge.Controllers
|
|||||||
};
|
};
|
||||||
|
|
||||||
url = Microsoft.AspNetCore.WebUtilities.QueryHelpers.AddQueryString("https://appcenter.intuit.com/connect/oauth2", queryParams);
|
url = Microsoft.AspNetCore.WebUtilities.QueryHelpers.AddQueryString("https://appcenter.intuit.com/connect/oauth2", queryParams);
|
||||||
// return Content($"AuthUrl: {url}");
|
// return Content($"AuthUrl: {url}");
|
||||||
return Redirect(url);
|
return Redirect(url);
|
||||||
|
|
||||||
//will ask for login creds and permission then will redirect back to the Get method above with:
|
//will ask for login creds and permission then will redirect back to the Get method above with:
|
||||||
@@ -77,6 +89,45 @@ namespace qbridge.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public async Task GetQBDiscoveryDocument()
|
||||||
|
{
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Get,
|
||||||
|
"https://developer.api.intuit.com/.well-known/openid_sandbox_configuration");
|
||||||
|
request.Headers.Add("Accept", "application/json");
|
||||||
|
request.Headers.Add("User-Agent", "AyaNova-QBridge");
|
||||||
|
|
||||||
|
var client = _clientFactory.CreateClient();
|
||||||
|
|
||||||
|
var response = await client.SendAsync(request);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string data = await response.Content.ReadAsStringAsync();
|
||||||
|
DiscoveryDoc = JObject.Parse(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DiscoveryDoc = null;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
// string baseUrl = "https://developer.api.intuit.com/.well-known/openid_sandbox_configuration"; //The 'using' will help to prevent memory leaks. //Create a new instance of HttpClient
|
||||||
|
// using (System.Net.Http.HttpClient client = new HttpClient())
|
||||||
|
|
||||||
|
// //Setting up the response...
|
||||||
|
|
||||||
|
// using (HttpResponseMessage res = await client.GetAsync(baseUrl))
|
||||||
|
// using (HttpContent content = res.Content)
|
||||||
|
// {
|
||||||
|
// string data = await content.ReadAsStringAsync();
|
||||||
|
// if (data != null)
|
||||||
|
// {
|
||||||
|
// Console.WriteLine(data);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Plan:
|
Plan:
|
||||||
Make a web APP and api that runs on our server and handles getting tokens from the QB Online oAuth2 endpoints
|
Make a web APP and api that runs on our server and handles getting tokens from the QB Online oAuth2 endpoints
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace qbridge
|
|||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
services.AddHttpClient();
|
||||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user