├── LICENSE.txt ├── OAuth_2 ├── C2QB_white_btn.png ├── Certificate │ ├── all.platform.intuit.com.pem │ ├── cacert.pem │ └── sandbox_all_platform_intuit_com.pem ├── Client.php ├── IntuitSignIn-lg.jpg ├── OAuth2PHPExample.php ├── OAuthOpenIDExample.php ├── RefreshToken.php ├── config.php ├── connectToQuickBooks.php ├── connected.php ├── index.php └── signInWithIntuit.php ├── README.md └── views ├── Callout.png ├── Ratesample.png ├── Thumbdown.png └── Thumbup.png /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2017 Intuit, Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /OAuth_2/C2QB_white_btn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntuitDeveloper/OAuth2_PHP/e74dd005b7b1e39c36ff17b3d5ac8055bf160868/OAuth_2/C2QB_white_btn.png -------------------------------------------------------------------------------- /OAuth_2/Certificate/all.platform.intuit.com.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIHDjCCBfagAwIBAgIQJIOggDKSPoIp0r8SxBDdizANBgkqhkiG9w0BAQsFADB+ 3 | MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd 4 | BgNVBAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxLzAtBgNVBAMTJlN5bWFudGVj 5 | IENsYXNzIDMgU2VjdXJlIFNlcnZlciBDQSAtIEc0MB4XDTE2MDgyMzAwMDAwMFoX 6 | DTE5MDgyNDIzNTk1OVowgYYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApDYWxpZm9y 7 | bmlhMRIwEAYDVQQHDAlTYW4gRGllZ28xFDASBgNVBAoMC0lOVFVJVCBJTkMuMRgw 8 | FgYDVQQLDA9DVE8tREVWLUlDUyBPcHMxHjAcBgNVBAMMFSoucGxhdGZvcm0uaW50 9 | dWl0LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAN5s33yZtRG7 10 | OtDJdjccwz9W0k0j1nLBQycmgNq2UkjwRnhxr8wFlFGC6rVRoK6OCgUCgAI5C6gD 11 | DM+XAdPFkb5APrXxLRGFsuWwMkHgXYEj1/9ETKb/fv8o4z8+jb0vPbT5wU6sX4Av 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ou/ 28 | TtWgrADkyVSApO8CIQDyv7EVweHIv3KqCt1ExNmMPW5iMM5AGEf8e9VfX6CxjwB2 29 | AGj2mPgfZIK+OozuuSgdTPxxUV1nk9RE0QpnrLtPT/vEAAABVrlU2iAAAAQDAEcw 30 | RQIhAJOMYAtUXUtnMWfqlgoXGm2mWK6DKxVkQUpP8FwyRkH5AiApJJCAQqXYlkmr 31 | e7QughCJoPVJFdWpB3+fLvPf9E1YXgB2AO5Lvbd1zmC64UJpH6vhnmajD35fsHLY 32 | gwDEe4l6qP3LAAABVrlU3EMAAAQDAEcwRQIgFxc38eRG8DmqD4qGTX7YXXoXwStR 33 | SKIGJlPkwqyU0U4CIQD2tJA7ZAQ7xW5XeIXB16kuqWeT/dtqG44VObIjk3FTRjAN 34 | BgkqhkiG9w0BAQsFAAOCAQEAhETs/qNnrEbZnJhT8pXAK8+taBbJa2VKBe3xc5pY 35 | +rKIAu/Dkhyeeg5IeGBloxRXKVCLmgB3ETMlW2alV1SfdMC1NPNDd+Uyj4dzsWyX 36 | IMSdypRjxrMMAuB5HPsjTze+YyTc/qQLXoFtOzkmUrdT2iFNEe1M9q6eXMZ/w/iD 37 | bhjorMyiKrvOJiSFL3s+q6RgzmVT1AbkvpgUoTWmfdl6SivzJgzwYD97KzuQr7fe 38 | WgCuq7JMSeW2KlwGzQEntyNOlOYDBi1Dd1V5KqVtyEUcAjdKkXvmBd+zlQYCqVlD 39 | KThcOUX0Gceu2O8i7/0Q1CyYKKxNkCpPt3MohS0IrdnTmw== 40 | -----END CERTIFICATE----- 41 | -------------------------------------------------------------------------------- /OAuth_2/Certificate/sandbox_all_platform_intuit_com.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIGNjCCBR6gAwIBAgIQRJCKaswR7ewplvxu83N7STANBgkqhkiG9w0BAQsFADB+ 3 | MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd 4 | BgNVBAs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E----- 37 | -------------------------------------------------------------------------------- /OAuth_2/Client.php: -------------------------------------------------------------------------------- 1 | client_id = $client_id; 27 | $this->client_secret = $client_secret; 28 | $this->setCertificate($certificate_file); 29 | } 30 | 31 | public function setCertificate($certificate_file){ 32 | $this->certificate_file = $certificate_file; 33 | if (!empty($this->certificate_file) && !is_file($this->certificate_file)) { 34 | throw new InvalidArgumentException('The certificate file was not found', InvalidArgumentException::CERTIFICATE_NOT_FOUND); 35 | } 36 | } 37 | 38 | public function callForOpenIDEndpoint($access_token, $url){ 39 | $authorizationHeaderInfo = $this->generateAccessTokenHeader($access_token); 40 | $http_header = array( 41 | 'Accept' => 'application/json', 42 | 'Authorization' => $authorizationHeaderInfo 43 | ); 44 | $result = $this->executeRequest($url , null, $http_header, self::HTTP_METHOD_GET); 45 | return $result; 46 | } 47 | 48 | private function generateAccessTokenHeader($access_token){ 49 | $authorizationheader = 'Bearer ' . $access_token; 50 | return $authorizationheader; 51 | } 52 | 53 | 54 | public function getAuthorizationURL($authorizationRequestUrl, $scope, $redirect_uri, $response_type, $state){ 55 | $parameters = array( 56 | 'client_id' => $this->client_id, 57 | 'scope' => $scope, 58 | 'redirect_uri' => $redirect_uri, 59 | 'response_type' => $response_type, 60 | 'state' => $state 61 | //The include_granted_scope is always set to false. No need to pass. 62 | //'include_granted_scope' => $include_granted_scope 63 | ); 64 | $authorizationRequestUrl .= '?' . http_build_query($parameters, null, '&', PHP_QUERY_RFC1738); 65 | return $authorizationRequestUrl; 66 | } 67 | 68 | public function getAccessToken($tokenEndPointUrl, $code, $redirectUrl, $grant_type){ 69 | if(!isset($grant_type)){ 70 | throw new InvalidArgumentException('The grant_type is mandatory.', InvalidArgumentException::INVALID_GRANT_TYPE); 71 | } 72 | 73 | $parameters = array( 74 | 'grant_type' => $grant_type, 75 | 'code' => $code, 76 | 'redirect_uri' => $redirectUrl 77 | ); 78 | $authorizationHeaderInfo = $this->generateAuthorizationHeader(); 79 | $http_header = array( 80 | 'Accept' => 'application/json', 81 | 'Authorization' => $authorizationHeaderInfo, 82 | 'Content-Type' => 'application/x-www-form-urlencoded' 83 | ); 84 | 85 | //Try catch??? 86 | $result = $this->executeRequest($tokenEndPointUrl , $parameters, $http_header, self::HTTP_METHOD_POST); 87 | return $result; 88 | } 89 | 90 | public function refreshAccessToken($tokenEndPointUrl, $grant_type, $refresh_token){ 91 | $parameters = array( 92 | 'grant_type' => $grant_type, 93 | 'refresh_token' => $refresh_token 94 | ); 95 | 96 | $authorizationHeaderInfo = $this->generateAuthorizationHeader(); 97 | $http_header = array( 98 | 'Accept' => 'application/json', 99 | 'Authorization' => $authorizationHeaderInfo, 100 | 'Content-Type' => 'application/x-www-form-urlencoded' 101 | ); 102 | $result = $this->executeRequest($tokenEndPointUrl , $parameters, $http_header, self::HTTP_METHOD_POST); 103 | return $result; 104 | } 105 | 106 | private function generateAuthorizationHeader(){ 107 | $encodedClientIDClientSecrets = base64_encode($this->client_id . ':' . $this->client_secret); 108 | $authorizationheader = 'Basic ' . $encodedClientIDClientSecrets; 109 | return $authorizationheader; 110 | } 111 | 112 | private function executeRequest($url, $parameters = array(), $http_header, $http_method) 113 | { 114 | 115 | $curl_options = array(); 116 | 117 | switch($http_method){ 118 | case self::HTTP_METHOD_GET: 119 | $curl_options[CURLOPT_HTTPGET] = 'true'; 120 | if (is_array($parameters) && count($parameters) > 0) { 121 | $url .= '?' . http_build_query($parameters); 122 | } elseif ($parameters) { 123 | $url .= '?' . $parameters; 124 | } 125 | break; 126 | case self:: HTTP_METHOD_POST: 127 | $curl_options[CURLOPT_POST] = '1'; 128 | if(is_array($parameters) && count($parameters) > 0){ 129 | $body = http_build_query($parameters); 130 | $curl_options[CURLOPT_POSTFIELDS] = $body; 131 | } 132 | break; 133 | default: 134 | break; 135 | } 136 | /** 137 | * An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100') 138 | */ 139 | if(is_array($http_header)){ 140 | $header = array(); 141 | foreach($http_header as $key => $value) { 142 | $header[] = "$key: $value"; 143 | } 144 | $curl_options[CURLOPT_HTTPHEADER] = $header; 145 | } 146 | 147 | $curl_options[CURLOPT_URL] = $url; 148 | $ch = curl_init(); 149 | 150 | //debug_backtrace 151 | //curl_setopt($ch, CURLOPT_VERBOSE, true); 152 | //$verbose = fopen('php://temp', 'w+'); 153 | //curl_setopt($ch, CURLOPT_STDERR, $verbose); 154 | 155 | 156 | curl_setopt_array($ch, $curl_options); 157 | // Require SSL Certificate 158 | 159 | if (!empty($this->certificate_file)) { 160 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 161 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 162 | //curl_setopt($ch, CURLOPT_CAPATH, $this->certificate_file); 163 | //curl_setopt($ch, CURLOPT_CAPATH, "/Library/WebServer/Documents/OAuth_2/Certificate/"); 164 | curl_setopt($ch, CURLOPT_CAINFO, $this->certificate_file); 165 | //curl_setopt($ch, CURLOPT_CAINFO, "/Library/WebServer/Documents/OAuth_2/Certificate/VeriSignClass3PublicPrimaryCertificationAuthority-G5.pem"); 166 | } else { 167 | // throw exception 168 | throw new Exception('Cannot find the SSL certificate_file.'); 169 | } 170 | 171 | 172 | //curl_setopt($ch, CURLINFO_HEADER_OUT, true); 173 | //Don't display, save it on result 174 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 175 | 176 | //Execute the Curl Request 177 | $result = curl_exec($ch); 178 | 179 | $headerSent = curl_getinfo($ch, CURLINFO_HEADER_OUT ); 180 | 181 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 182 | 183 | 184 | $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); 185 | if ($curl_error = curl_error($ch)) { 186 | throw new Exception($curl_error); 187 | } else { 188 | $json_decode = json_decode($result, true); 189 | } 190 | curl_close($ch); 191 | 192 | //var_dump($json_decode); 193 | return $json_decode; 194 | } 195 | } 196 | ?> 197 | -------------------------------------------------------------------------------- /OAuth_2/IntuitSignIn-lg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntuitDeveloper/OAuth2_PHP/e74dd005b7b1e39c36ff17b3d5ac8055bf160868/OAuth_2/IntuitSignIn-lg.jpg -------------------------------------------------------------------------------- /OAuth_2/OAuth2PHPExample.php: -------------------------------------------------------------------------------- 1 | getAuthorizationCode($authorizationRequestUrl, $scope, $redirect_uri, $response_type, $state, $include_granted_scope); 31 | //unset $_SESSION global variables 32 | unset($_SESSION['access_token']); 33 | unset($_SESSION['refresh_token']); 34 | $authUrl = $client->getAuthorizationURL($authorizationRequestUrl, $scope, $redirect_uri, $response_type, $state); 35 | header("Location: ".$authUrl); 36 | exit(); 37 | } 38 | else 39 | { 40 | $code = $_GET["code"]; 41 | $responseState = $_GET['state']; 42 | if(strcmp($state, $responseState) != 0){ 43 | throw new Exception("The state is not correct from Intuit Server. Consider your app is hacked."); 44 | } 45 | $result = $client->getAccessToken($tokenEndPointUrl, $code, $redirect_uri, $grant_type); 46 | //record them in the session variable 47 | $_SESSION['access_token'] = $result['access_token']; 48 | $_SESSION['refresh_token'] = $result['refresh_token']; 49 | 50 | header("Location: http://localhost/OAuth2_PHP/OAuth_2/index.php"); 51 | exit(); 52 | 53 | } 54 | 55 | ?> 56 | -------------------------------------------------------------------------------- /OAuth_2/OAuthOpenIDExample.php: -------------------------------------------------------------------------------- 1 | getAuthorizationURL($authorizationRequestUrl, $scope, $redirect_uri, $response_type, $state); 38 | header("Location: ".$authUrl); 39 | exit(); 40 | } 41 | else 42 | { 43 | $code = $_GET["code"]; 44 | $responseState = $_GET['state']; 45 | if(strcmp($state, $responseState) != 0){ 46 | throw new Exception("The state is not correct from Intuit Server. Consider your app is hacked."); 47 | } 48 | $result = $client->getAccessToken($tokenEndPointUrl, $code, $redirect_uri, $grant_type); 49 | $openID_accessToken = $result['access_token']; 50 | //Use Sandbox certificate 51 | $client->setCertificate($certFilePathOpenID); 52 | $userInfo = $client->callForOpenIDEndpoint($openID_accessToken, $usrInfoURL); 53 | $_SESSION['userInfo'] = $userInfo; 54 | 55 | header("Location: http://localhost/OAuth2_PHP/OAuth_2/index.php"); 56 | exit(); 57 | } 58 | 59 | ?> 60 | -------------------------------------------------------------------------------- /OAuth_2/RefreshToken.php: -------------------------------------------------------------------------------- 1 | refreshAccessToken($tokenEndPointUrl, $grant_type, $refresh_token); 27 | $_SESSION['access_token'] = $result['access_token']; 28 | $_SESSION['refresh_token'] = $result['refresh_token']; 29 | 30 | 31 | echo ''; 34 | 35 | }else{ 36 | $_SESSION['access_token'] = null; 37 | $_SESSION['refresh_token'] = null; 38 | 39 | echo ''; 42 | } 43 | 44 | ?> 45 | -------------------------------------------------------------------------------- /OAuth_2/config.php: -------------------------------------------------------------------------------- 1 | '', //Example https://appcenter.intuit.com/connect/oauth2', 4 | 'tokenEndPointUrl' => '', //Example https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', 5 | 'client_id' => '', //Example 'Q0wDe6WVZMzyu1SnNPAdaAgeOAWNidnVRHWYEUyvXVbmZDRUfQ', 6 | 'client_secret' => '', //Example 'R9IttrvneexLcUZbj3bqpmtsu5uD9p7UxNMorpGd', 7 | 'oauth_scope' => '', //Example 'com.intuit.quickbooks.accounting', 8 | 'openID_scope' => '', //Example 'openid profile email', 9 | 'oauth_redirect_uri' => '', //Example https://d1eec721.ngrok.io/OAuth_2/OAuth2PHPExample.php', 10 | 'openID_redirect_uri' => '',//Example 'https://d1eec721.ngrok.io/OAuth_2/OAuthOpenIDExample.php', 11 | 'mainPage' => '', //Example https://d1eec721.ngrok.io/OAuth_2/index.php', 12 | 'refreshTokenPage' => '', //Example https://d1eec721.ngrok.io/OAuth_2/RefreshToken.php' 13 | ) 14 | ?> 15 | -------------------------------------------------------------------------------- /OAuth_2/connectToQuickBooks.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | My Connect Page 16 | 17 | 18 | Retrieve OAuth 2 Tokens from Sessions:"; 22 | $tokens = array( 23 | 'access_token' => $_SESSION['access_token'], 24 | 'refresh_token' => $_SESSION['refresh_token'] 25 | ); 26 | var_dump($tokens); 27 | echo "
28 | Refresh Token 29 |
"; 30 | echo "
31 | Clean Session 32 |
"; 33 | }else{ 34 | echo "

Please Complete the \"Connect to QuickBooks\" OAuth 2 flow:

"; 35 | echo '
Add the OAuth 2 Consumer Key and OAuth 2 Consumer Secret of your application to config.php file to enable OAuth2 flow.

36 |
Add the oauth_redirect_uri to config.php file. This URL is used by Intuit to redirect the user to your page when user authorized your app.

37 |
Click on the button below to start "Connect to QuickBooks"
'; 38 | echo "

"; 39 | } 40 | 41 | echo "

Please Complete the \"Sign In With Intuit\" flow:

"; 42 | echo '
Add the OAuth 2 Consumer Key and OAuth 2 Consumer Secret of your application to config.php file to enable OpenID flow.

43 |
Add the openID_redirect_uri to config.php file. This URL is used by Intuit to redirect the user to your page when the user agreed for your app retrieving their personal information.

44 |
Click on the button below to start "Sign in with Intuit"
'; 45 | //$loginStringGeneration = ""; 46 | echo ""; 47 | //} 48 | 49 | ?> 50 | 51 | -------------------------------------------------------------------------------- /OAuth_2/connected.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | OAuth2 Sample App - Intuit 4 | 5 | 6 | 7 | 8 | Home 9 |

Connected!

10 | 11 | 12 | -------------------------------------------------------------------------------- /OAuth_2/index.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | My Connect Page 16 | 17 | 18 | Retrieve OAuth 2 Tokens from Sessions:"; 22 | $tokens = array( 23 | 'access_token' => $_SESSION['access_token'], 24 | 'refresh_token' => $_SESSION['refresh_token'] 25 | ); 26 | 27 | echo "

Access Token: {$_SESSION['access_token']}

"; 28 | echo "

Refresh Token: {$_SESSION['refresh_token']}

"; 29 | 30 | echo "
31 | Refresh Token 32 |
"; 33 | echo "
34 | Clean Session 35 |
"; 36 | } else if ($_SESSION['userInfo']) { 37 | echo "

User information obtained from open id call

"; 38 | echo "

Given Name: {$_SESSION['userInfo']['givenName']}

"; 39 | echo "

Family Name: {$_SESSION['userInfo']['familyName']}

"; 40 | echo "

Email: {$_SESSION['userInfo']['email']}

"; 41 | echo "

Phone Number: {$_SESSION['userInfo']['phoneNumber']}

"; 42 | echo "

Address: {$_SESSION['userInfo']['address']['streetAddress']},   43 | {$_SESSION['userInfo']['address']['locality']},   44 | {$_SESSION['userInfo']['address']['region']} - {$_SESSION['userInfo']['address']['postalCode']} 45 |

"; 46 | } else{ 47 | echo "

Please Complete the \"Connect to QuickBooks\" OAuth 2 flow:

"; 48 | echo '
Add the OAuth 2 Consumer Key and OAuth 2 Consumer Secret of your application to config.php file to enable OAuth2 flow.

49 |
Add the oauth_redirect_uri to config.php file. This URL is used by Intuit to redirect the user to your page when user authorized your app.

50 |
Click on the button below to start "Connect to QuickBooks"
'; 51 | echo "

"; 52 | echo "

Please Complete the \"Sign In With Intuit\" flow:

"; 53 | echo '
Add the OAuth 2 Consumer Key and OAuth 2 Consumer Secret of your application to config.php file to enable OpenID flow.

54 |
Add the openID_redirect_uri to config.php file. This URL is used by Intuit to redirect the user to your page when the user agreed for your app retrieving their personal information.

55 |
Click on the button below to start "Sign in with Intuit"
'; 56 | echo ""; 57 | } 58 | ?> 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /OAuth_2/signInWithIntuit.php: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Rate your Sample](views/Ratesample.png)][ss1][![Yes](views/Thumbup.png)][ss2][![No](views/Thumbdown.png)][ss3] 2 | 3 | # OAuth2_PHP 4 | 5 | 6 | 7 | **QuickBooks OAuth2 Sample app for PHP** 8 | 9 | The Intuit Developer team has written this OAuth 2.0 Sample App in PHP to provide working examples of OAuth 2.0 concepts, and how to integrate with Intuit endpoints. 10 | 11 | **What is included** 12 | 13 | The Sample app demonstrate three parts: 14 | 15 | 1) How to generate OAuth tokens 16 | 17 | 2) How to use OpenID to get User information 18 | 19 | 3) Refresh token and logout 20 | 21 | **Getting Started** 22 | 23 | Before beginning, it may be helpful to have a basic understanding of OAuth 2.0 concepts. There are plenty of tutorials and guides to get started with OAuth 2.0. Check out the docs on https://developer.intuit.com/ 24 | 25 | **PreRequisites** 26 | 27 | PHP version > 5.6 28 | 29 | ngrok 30 | 31 | openSSL 32 | 33 | DONOT USE LOCAL HOST. USE NGROK HTTPS URL. 34 | 35 | **Setup** 36 | 37 | ***Certificate Setup*** 38 | 39 | The core of HTTPS is the handshake process. During the handshake, clients will verify that the server is exactly the server they want to communicate with -- by verifying the certificate chain on the server. For ease of use, this sample program has already provided certificate with the app under Certificate folder. For those who want to know how to get those certificate, here is the step: 40 | 41 | 1) Download the server certificate from the websites. You can follow the instruction here: Make sure you choose the X.509 format with Chain(cer) 42 | 43 | 2) Use OpenSSL to convert the crt file to pem file: 44 | 45 | openssl x509 -inform der -in certificate.cer -out certificate.pem 46 | 47 | 48 | ***ngrok Setup*** 49 | 50 | Since the redirected url has to be through SSL, we recommand ngrok here. Ngrok will simply assigns a temporary publicly accessible domain name (ex: https://abc123.ngrok.io) to forward to some port on your local machine (in this case, port 80). 51 | 52 | For how to use ngrok, follow the instruction Here: 53 | 54 | 55 | ***Configuring your app*** 56 | 57 | All configuration for this app is located in config.php Locate and open this file. 58 | 59 | We will need to update 6 items: 60 | 61 | client_id 62 | 63 | client_secret 64 | 65 | oauth_redirect_uri 66 | 67 | openID_redirect_uri 68 | 69 | mainPage 70 | 71 | refreshTokenPage 72 | 73 | 74 | First 4 values must match exactly with what is listed in your app settings on developer.intuit.com. If you haven't already created an app, you may do so there. Please read on for important notes about client credentials, scopes, and redirect urls. 75 | 76 | Once you have created an app on Intuit's Developer Portal, you can find your credentials (Client ID and Client Secret) under the "Keys" tab. You will also find a section to enter your Redirect URI here. 77 | 78 | mainPage is the home page that located in your own server. 79 | refreshTokenPage is the page that has the script for running refreshtokens. 80 | 81 | You can refer to the commented value in the config.php file there. 82 | 83 | **Scopes** 84 | 85 | While you are in config.php, you'll notice the scope configurations. 86 | 87 | 'oauth_scope' => 'com.intuit.quickbooks.accounting', 88 | 'openID_scope' => 'openid profile email', 89 | 90 | It is important to ensure that the scopes your are requesting match the scopes allowed on the Developer Portal. 91 | 92 | **Run your app!** 93 | 94 | * setting up both Developer Portal and your config.php 95 | * Run the ngrok. For easy of use, this sample is running on port 80(default port) 96 | ./ngrok http 80 97 | * Then you will get the https url mapping to the localhost port-> https://d1eec721.ngrok.io 98 | * Download the project and put it under your server. For mac, you can put it under Apache Server root: /Library/WebServer/Documents 99 | * Use this as reference and paste this in browser- 100 | https://d1eec721.ngrok.io/OAuth_2/index.php and do enter. 101 | (Do not use localhost. We use seesion to record values. The session will only work with the same domain) 102 | 103 | **Notice** 104 | 105 | The Sample code use: 106 | ~~~php 107 | window.opener.location.href = window.opener.location.href; 108 | ~~~ 109 | 110 | as the refresh page javscript code. Therefore, please use NGORK URL in your URI. DO NOT USE LOCALHOST 111 | 112 | [ss1]: # 113 | [ss2]: https://customersurveys.intuit.com/jfe/form/SV_9LWgJBcyy3NAwHc?check=Yes&checkpoint=OAuth2_PHP&pageUrl=github 114 | [ss3]: https://customersurveys.intuit.com/jfe/form/SV_9LWgJBcyy3NAwHc?check=No&checkpoint=OAuth2_PHP&pageUrl=github 115 | -------------------------------------------------------------------------------- /views/Callout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntuitDeveloper/OAuth2_PHP/e74dd005b7b1e39c36ff17b3d5ac8055bf160868/views/Callout.png -------------------------------------------------------------------------------- /views/Ratesample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntuitDeveloper/OAuth2_PHP/e74dd005b7b1e39c36ff17b3d5ac8055bf160868/views/Ratesample.png -------------------------------------------------------------------------------- /views/Thumbdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntuitDeveloper/OAuth2_PHP/e74dd005b7b1e39c36ff17b3d5ac8055bf160868/views/Thumbdown.png -------------------------------------------------------------------------------- /views/Thumbup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IntuitDeveloper/OAuth2_PHP/e74dd005b7b1e39c36ff17b3d5ac8055bf160868/views/Thumbup.png --------------------------------------------------------------------------------