This commit is contained in:
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Formatting;
|
||||
|
||||
namespace qbridge.Controllers
|
||||
{
|
||||
@@ -60,13 +61,14 @@ namespace qbridge.Controllers
|
||||
}
|
||||
|
||||
|
||||
|
||||
bugbug: It's not prompting for the company I want like the playground does...what's up with that? Is it because I need to follow the OpenID method rather than the "web app" method??
|
||||
[HttpGet("Start/{qboid}")]
|
||||
public async Task<IActionResult> GetAsync([FromQuery]string qboid)
|
||||
public async Task<IActionResult> GetAsync([FromRoute]string qboid)
|
||||
{
|
||||
|
||||
if(string.IsNullOrWhiteSpace(qboid)){
|
||||
|
||||
if (string.IsNullOrWhiteSpace(qboid))
|
||||
{
|
||||
return BadRequest("QBOID value is required");
|
||||
}
|
||||
|
||||
//GET THE DISCOVERY DOCUMENT
|
||||
@@ -94,7 +96,7 @@ namespace qbridge.Controllers
|
||||
{"scope", "openid" },
|
||||
{"redirect_uri",REDIRECT_URI },
|
||||
{"response_type","code"},
|
||||
{"state","MyUniqueStateID"}
|
||||
{"state",qboid}
|
||||
};
|
||||
|
||||
url = Microsoft.AspNetCore.WebUtilities.QueryHelpers.AddQueryString(AuthorizationEndpoint, queryParams);
|
||||
@@ -234,10 +236,24 @@ TOKEN: {
|
||||
|
||||
|
||||
|
||||
[HttpGet("Revoke/{id}")]
|
||||
public async Task<IActionResult> RevokeAsync()
|
||||
[HttpGet("Revoke/{tokenToRevoke}")]
|
||||
public async Task<IActionResult> RevokeAsync([FromRoute]string tokenToRevoke)
|
||||
{
|
||||
//Revoke the access token for the app for the unique ID specified
|
||||
/*
|
||||
|
||||
POST https://developer.api.intuit.com/v2/oauth2/tokens/revoke HTTP/1.1
|
||||
Accept: application/json
|
||||
Authorization: Basic UTM0dVBvRDIwanp2OUdxNXE1dmlMemppcTlwM1d2
|
||||
NzRUdDNReGkwZVNTTDhFRWwxb0g6VEh0WEJlR3dheEtZSlVNaFhzeGxma1l
|
||||
XaFg3ZlFlRzFtN2szTFRwbw==
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"token": "{bearerToken or refreshToken}"
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//GET THE DISCOVERY DOCUMENT
|
||||
//Discovery document contains the actual current endpoints to use for various ops
|
||||
@@ -255,35 +271,36 @@ TOKEN: {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, revocation_endpoint);
|
||||
request.Headers.Add("Accept", "application/json");
|
||||
request.Headers.Add("User-Agent", "AyaNova-QBridge");
|
||||
request.Headers.Add("Authorization", "Basic " + Base64Encode(CLIENT_ID + ":" + CLIENT_SECRET));
|
||||
|
||||
var bodyParams = new Dictionary<string, string>()
|
||||
{
|
||||
{"code", code },
|
||||
{"redirect_uri", REDIRECT_URI },
|
||||
{"grant_type","authorization_code"}
|
||||
};
|
||||
request.Content = new FormUrlEncodedContent(bodyParams);
|
||||
// var bodyParams = new Dictionary<string, string>()
|
||||
// {
|
||||
// {"code", code },
|
||||
// {"redirect_uri", REDIRECT_URI },
|
||||
// {"grant_type","authorization_code"}
|
||||
// };
|
||||
|
||||
|
||||
string jfrag = $"{{\"token\":\"{tokenToRevoke}\"}}";
|
||||
|
||||
request.Content = new StringContent(jfrag, System.Text.Encoding.UTF8, "application/json");
|
||||
|
||||
var client = _clientFactory.CreateClient();
|
||||
|
||||
var response = await client.SendAsync(request);
|
||||
|
||||
JObject AccessTokenObject = null;
|
||||
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string data = await response.Content.ReadAsStringAsync();
|
||||
AccessTokenObject = JObject.Parse(data);
|
||||
return Content("Token revoked");
|
||||
}
|
||||
else
|
||||
{
|
||||
AccessTokenObject = null;
|
||||
return Content("Token revocation FAILED!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user