diff --git a/Controllers/AuthController.cs b/Controllers/AuthController.cs index d93f817..f5778c1 100644 --- a/Controllers/AuthController.cs +++ b/Controllers/AuthController.cs @@ -18,6 +18,11 @@ namespace qbridge.Controllers public const string CLIENT_ID = "ABj70Wv5gDauFd9KgKFwuvpQjfzTwEgodEG8tnBbS8mSQhNrZJ"; public const string CLIENT_SECRET = "XUmJyvEcEuwQuyhARUAm0a8G3gzbEAeMiATCLyFZ"; public const string REDIRECT_URI = "https://localhost:5001/OAuthRedirect"; + public const string DISCOVERY_DOCUMENT_URL = "https://developer.api.intuit.com/.well-known/openid_sandbox_configuration"; + + //current 2019 fall disco doc urls + //Sandbox: https://developer.api.intuit.com/.well-known/openid_sandbox_configuration + //Production: https://developer.api.intuit.com/.well-known/openid_configuration //used for discovery document //https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.0 @@ -167,7 +172,6 @@ namespace qbridge.Controllers /* Actual response example: - TOKEN: { "x_refresh_token_expires_in": 8726400, @@ -178,8 +182,6 @@ namespace qbridge.Controllers } */ - //https://localhost:5001/oauthredirect?state=bar&code=foo - // return Content($"State: {state}, Code: {code}"); } public static string Base64Encode(string plainText) @@ -188,19 +190,21 @@ namespace qbridge.Controllers return System.Convert.ToBase64String(plainTextBytes); } + + //This block gets the QuickBooks official endpoints rather than statically coding them public async Task GetQBDiscoveryDocument() { /* - + Example: issuer:"https://oauth.platform.intuit.com/op/v1", - authorization_endpoint:"https://appcenter.intuit.com/connect/oauth2", - token_endpoint:"https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer", - userinfo_endpoint:"https://accounts.intuit.com/v1/openid_connect/userinfo", - revocation_endpoint:"https://developer.API.intuit.com/v2/oauth2/tokens/revoke", - jwks_uri:"https://oauth.platform.intuit.com/op/v1/jwks", + authorization_endpoint:"https://appcenter.intuit.com/connect/oauth2", + token_endpoint:"https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer", + userinfo_endpoint:"https://accounts.intuit.com/v1/openid_connect/userinfo", + revocation_endpoint:"https://developer.API.intuit.com/v2/oauth2/tokens/revoke", + jwks_uri:"https://oauth.platform.intuit.com/op/v1/jwks" */ - var request = new HttpRequestMessage(HttpMethod.Get, - "https://developer.api.intuit.com/.well-known/openid_sandbox_configuration"); + + var request = new HttpRequestMessage(HttpMethod.Get, DISCOVERY_DOCUMENT_URL); request.Headers.Add("Accept", "application/json"); request.Headers.Add("User-Agent", "AyaNova-QBridge"); @@ -217,46 +221,24 @@ namespace qbridge.Controllers { 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); - // } - // } + return; } - - - - - [HttpGet("Revoke/{tokenToRevoke}")] public async Task 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}" -} - + /* + 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