Giter Club home page Giter Club logo

oauth2_php's Introduction

Rate your SampleYesNo

OAuth2_PHP

QuickBooks OAuth2 Sample app for PHP

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.

What is included

The Sample app demonstrate three parts:

  1. How to generate OAuth tokens

  2. How to use OpenID to get User information

  3. Refresh token and logout

Getting Started

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/

PreRequisites

PHP version > 5.6

ngrok

openSSL

DONOT USE LOCAL HOST. USE NGROK HTTPS URL.

Setup

Certificate Setup

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:

  1. Download the server certificate from the websites. You can follow the instruction here: http://docs.bvstools.com/home/ssl-documentation/exporting-certificate-authorities-cas-from-a-website Make sure you choose the X.509 format with Chain(cer)

  2. Use OpenSSL to convert the crt file to pem file:

openssl x509 -inform der -in certificate.cer -out certificate.pem

ngrok Setup

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).

For how to use ngrok, follow the instruction Here: https://ngrok.com/download

Configuring your app

All configuration for this app is located in config.php Locate and open this file.

We will need to update 6 items:

client_id

client_secret

oauth_redirect_uri

openID_redirect_uri

mainPage

refreshTokenPage

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.

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.

mainPage is the home page that located in your own server. refreshTokenPage is the page that has the script for running refreshtokens.

You can refer to the commented value in the config.php file there.

Scopes

While you are in config.php, you'll notice the scope configurations.

  'oauth_scope' => 'com.intuit.quickbooks.accounting',
  'openID_scope' => 'openid profile email',

It is important to ensure that the scopes your are requesting match the scopes allowed on the Developer Portal.

Run your app!

  • setting up both Developer Portal and your config.php
  • Run the ngrok. For easy of use, this sample is running on port 80(default port) ./ngrok http 80
  • Then you will get the https url mapping to the localhost port-> https://d1eec721.ngrok.io
  • Download the project and put it under your server. For mac, you can put it under Apache Server root: /Library/WebServer/Documents
  • Use this as reference and paste this in browser- https://d1eec721.ngrok.io/OAuth_2/index.php and do enter. (Do not use localhost. We use seesion to record values. The session will only work with the same domain)

Notice

The Sample code use:

window.opener.location.href = window.opener.location.href;

as the refresh page javscript code. Therefore, please use NGORK URL in your URI. DO NOT USE LOCALHOST

oauth2_php's People

Contributors

aakashmalhotra avatar bsivalingam avatar diana-derose avatar hlu2 avatar rkasaraneni20 avatar tvaughan73 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oauth2_php's Issues

I am getting an error when I use this sample app

Hi, I am new to Intuit developer community and trying to use OAuth2 with Laravel 5.4 but getting the error page when I click on Connect to QB button.

We're sorry! We're experiencing some problem. Please try again later. Any help will be much appreciated.
oauth2-php-error

Old Intuit Developer Account Not Showing OAuth2 Support on Keys page for App

I tried the following steps multiple times but was not successful in getting the new ClientID and ClientSecret for OAuth2, kept getting the old AppToken, ConsumerKey/Secret values and no way to configure RedirectURI even for newly created App.

  1. Create App
  2. Select Accounting and/or Payment API
  3. Intuit Single Sign On --> Yes

The ONLY workaround seems to be to create a new account and create an app in the new account then I get the OAuth2 ClientID/Secret.

@hlu2 Any help here would be much appreciated.

Keep getting error when using a sand-box clientkey and secret key

Good Day...

I was trying to test OAuth with this sample but I keep getting error when redirected to https://appcenter.intuit.com/connect/oauth2?client_id=L0wfLei7A5qHX3OU62CU0DWMZyifQr6DINORlF4HdoyxQ36F8z&scope=com.intuit.quickbooks.accounting&redirect_uri=https%3A%2F%2Fqb.dagnum.com%2Ftest%2FOAuth2PHPExample.php&response_type=code&state=RandomState .. I couldn't even reach to the page wher it asks you to authorize the app.. however I could reach the authorize your app page If I do use the sample ClientKey and ClientKeySecret but still get an error after clicking authorize..

heres my config.php

<?php
return array(
  
  'authorizationRequestUrl' => 'https://appcenter.intuit.com/connect/oauth2', //Example https://appcenter.intuit.com/connect/oauth2',
  'tokenEndPointUrl' => 'hhttps://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', //Example https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer',
  'client_id' => 'L0wfLei7A5qHX3OU62CU0DWMZyifQr6DINORlF4HdoyxQ36F8z', //Example 'Q0wDe6WVZMzyu1SnNPAdaAgeOAWNidnVRHWYEUyvXVbmZDRUfQ',
  'client_secret' => '63NHnCNltXUXVo6RUFQADHKHcNSdDuPuwHCi0KmW', //Example 'R9IttrvneexLcUZbj3bqpmtsu5uD9p7UxNMorpGd',
  'oauth_scope' => 'com.intuit.quickbooks.accounting', //Example 'com.intuit.quickbooks.accounting',
  'openID_scope' => '', //Example 'openid profile email',
  'oauth_redirect_uri' => 'https://qb.dagnum.com/test/OAuth2PHPExample.php', //Example https://d1eec721.ngrok.io/OAuth_2/OAuth2PHPExample.php',
  'openID_redirect_uri' => '',//Example 'https://d1eec721.ngrok.io/OAuth_2/OAuthOpenIDExample.php',
  'mainPage' => 'https://qb.dagnum.com/test', //Example https://d1eec721.ngrok.io/OAuth_2/index.php',
  'refreshTokenPage' => 'https://qb.dagnum.com/test/RefreshToken.php', //Example https://d1eec721.ngrok.io/OAuth_2/RefreshToken.php'
)
 ?>

its so hard to debug as it doesnt give me a comprehensive error message.. just "We're sorry!
We're experiencing some problems. Please try again later."

how do I fix this please

realmId is not set/displayed

OAuth2PHPExample.php should set the session value for the realmId, ex: $_SESSION['realmId'] = $_GET['realmId']; and index.php should display the realmId value along with the token values.

OAuth2PHPExample.php

Fatal error: Uncaught exception 'Exception' with message 'error setting certificate verify locations: CAfile: ./Certificate/cacert.pem CApath: none' in C:\xampp\htdocs\OAuth2_PHP\OAuth_2\Client.php:186 Stack trace: #0 C:\xampp\htdocs\OAuth2_PHP\OAuth_2\Client.php(86): Client->executeRequest('https://oauth.p...', Array, Array, 'POST') #1 C:\xampp\htdocs\OAuth2_PHP\OAuth_2\OAuth2PHPExample.php(48): Client->getAccessToken('https://oauth.p...', 'Q011528139602Ph...', 'https://d880952...', 'authorization_c...') #2 {main} thrown in C:\xampp\htdocs\OAuth2_PHP\OAuth_2\Client.php on line 186

Error: appcenter.intuit.com redirected you too many times

Here's my config.php:

<?php return array( 'authorizationRequestUrl' => 'https://appcenter.intuit.com/connect/oauth2', 'tokenEndPointUrl' => 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', 'client_id' => 'Q0xRYbop24Ggh4a04WERTzfhjygqc7aHC8hiQWH1JZr9Fe6Lzl', 'client_secret' => 'Fb1yxxLyinA7opMbyIm6SSmhCUNPOSXXXXXXXXXX', 'oauth_scope' => '.com.intuit.quickbooks.accounting', 'openID_scope' => 'openid profile email', 'oauth_redirect_uri' => 'https://5c0ec91b.ngrok.io/oauth/OAuth_2/OAuth2PHPExample.php', 'openID_redirect_uri' => 'https://5c0ec91b.ngrok.io/oauth/OAuth_2/OAuthOpenIDExample.php', 'mainPage' => 'https://5c0ec91b.ngrok.io/oauth/OAuth_2/index.php', 'refreshTokenPage' => 'https://5c0ec91b.ngrok.io/oauth/OAuth_2/RefreshToken.php', ) ?>

With index.php, these are displayed:

Add the OAuth 2 Consumer Key and OAuth 2 Consumer Secret of your application to config.php file to enable OAuth2 flow.

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.

Click on the button below to start "Connect to QuickBooks"

How do I go about this since all the info needed are already provided? The error stated in the title is when I click the "Connect to QuickBooks" button.

Issue with cacert.pem

I have tried all different ways of generating the ssl cert to work with this script. I have downloaded the Mozilla one. I have used openssl to regenerate a pem from cer file that I got from ngrok but I keep getting this error.

Fatal error: Uncaught Exception: error setting certificate verify locations: CAfile: ./Certificate/cacert-2017-06-07.pem CApath: none in C:\wamp64\www\plugins\quickbooks\Client.php:186 Stack trace: #0 C:\wamp64\www\plugins\quickbooks\Client.php(86): Client->executeRequest('https://oauth.p...', Array, Array, 'POST') #1 C:\wamp64\www\plugins\quickbooks\OAuth2PHPExample.php(45): Client->getAccessToken('https://oauth.p...', 'L01150395379466...', 'https://aefb615...', 'authorization_c...') #2 {main} thrown in C:\wamp64\www\plugins\quickbooks\Client.php on line 186

Realm Id still given after auth?

Hi, #9 it is said that the realmId is in the response upon successful authentication. Is this still true, because running your example I do not see a realmId.

Thank you!

Realm ID

From where would I get a customer's realm ID during the OAuth process?

I have Urgent problem, Can't get my access token at all!!

I'm implementing credit card charge of Quickbooks Payment API ok this's done but I get the access token through Curl manually, so I want to get it from authorization code to access token automatically with Curl PHP.

I replaced my credentials in the config.php but I still redirect to quickbooks api developer to sign in with my account which bothering the company so much!!!

Also I get this error when I try to get my access token I get this error and the image preview that the auth code in the url

Fatal error: Uncaught Exception: error setting certificate verify locations: CAfile: ./Certificate/cacert.pem CApath: none in C:\xampp\htdocs\roife_quickbooks\OAuth2_PHP-master\OAuth_2\Client.php:193 Stack trace: #0 C:\xampp\htdocs\roife_quickbooks\OAuth2_PHP-master\OAuth_2\Client.php(91): Client->executeRequest('https://oauth.p...', Array, Array, 'POST') #1 C:\xampp\htdocs\roife_quickbooks\OAuth2_PHP-master\OAuth_2\OAuth2PHPExample.php(39): Client->getAccessToken('https://oauth.p...', 'AB11662138803bz...', 'https://5917-41...', 'authorization_c...') #2 {main} thrown in C:\xampp\htdocs\roife_quickbooks\OAuth2_PHP-master\OAuth_2\Client.php on line 193

image

SSL certificate problem: unable to get local issuer certificate

PHP Fatal error: Uncaught Exception: SSL certificate problem: unable to get local issuer certificate in /Applications/MAMP/htdocs/OAuth2_PHP-master/OAuth_2/Client.php:186
Stack trace:
#0 /Applications/MAMP/htdocs/OAuth2_PHP-master/OAuth_2/Client.php(86): Client->executeRequest('https://oauth.p...', Array, Array, 'POST')
#1 /Applications/MAMP/htdocs/OAuth2_PHP-master/OAuth_2/OAuth2PHPExample.php(48): Client->getAccessToken('https://oauth.p...', 'Q011501220483w7...', 'https://ef0e5c5...', 'authorization_c...')
#2 {main}
thrown in /Applications/MAMP/htdocs/OAuth2_PHP-master/OAuth_2/Client.php on line 186

@hlu2 Any help here would be much appreciated.

keep on getting Missing grantUrl in setup function

i have been following all the steps mentioned in the documentation of this code base as well as the official documentation including serving my app in ngrok..etc however; whenever i click on the connect to QBO button, i get this error from the console.log saying: Missing grantUrl in setup function in the file: https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere-1.3.3.js

Can someone please share with me what could the problem be in this case.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.