PHPackages                             globalvisionmedia/oauth2-myob - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. globalvisionmedia/oauth2-myob

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

globalvisionmedia/oauth2-myob
=============================

MYOB OAuth 2.0 Client Provider for The PHP League OAuth2-Client

v1.4(3y ago)0583MITPHPPHP &gt;=5.5.0

Since Sep 12Pushed 3y ago1 watchersCompare

[ Source](https://github.com/globalvisionmedia/oauth2-myob)[ Packagist](https://packagist.org/packages/globalvisionmedia/oauth2-myob)[ RSS](/packages/globalvisionmedia-oauth2-myob/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (5)Used By (0)

MYOB Provider for OAuth 2.0 Client
==================================

[](#myob-provider-for-oauth-20-client)

This package provides MYOB OAuth 2.0 support for the PHP League's OAuth 2.0 Client.

Installation
============

[](#installation)

```
composer require globalvisionmedia/oauth2-myob

```

Obtaining an MYOB access key
============================

[](#obtaining-an-myob-access-key)

1. To get a key you will need to be part of the MYOB Developer Program ()
2. After you obtain an account, log in and click the "Developer" tab of my.myob.com.au
3. Click the Register App button to create a key
4. The redirect API must be exactly the same (including the http:// or https://) as the redirectUri below and is the URL of your application

Usage
=====

[](#usage)

Usage is the same as The League's OAuth client, using \\GlobalVisionMedia\\OAuth2\\MYOBClient\\Provider\\MYOB as the provider, except for the following:

1. MYOB does not rely exclusively on OAuth2 to log you in. OAUth2 is used to provide access to the APIs but not to your MYOB data file. This requires a second login which returns a "Company URL". This provider handles both logins but requires you to provide your MYOB login details in addition to the standard OAUth2 credentials. (see Authorisation Code Flow, below)
2. MYOB's APIs are throttled - the documented limit is 8 calls per second (and a large number per day) but the throttling appears to be buggy and you will likely find that you receive API Access Limit Exceeded errors no matter what limits you impose unfortunately. However you will be able to create an application that works fairly reliably if you follow the guidelines under Sample Application (below) qnd add a failsafe that detects the throttling, pauses and retries.

Instantiation
=============

[](#instantiation)

```
$provider = new \GlobalVisionMedia\OAuth2\MYOBClient\Provider\MYOB([
    'clientId'                => 'yourId',          // The Key assigned to you by MYOB
    'clientSecret'            => 'yourSecret',      // The Secret assigned to you by MYOB
    'redirectUri'             => 'yourRedirectUri'  // The Redirect Uri you specified for your app on MYOB
    'username'                => 'yourUsername',    // The username you use when you log into MYOB
    'password'                => 'yourPassword',    // The password you use to log into MYOB
    'companyName'             => 'yourCompany'      // The name of your company file. This appears in the "Welcome" screen when you log into MYOB
]);

```

Tip (also applies to other providers)
=====================================

[](#tip-also-applies-to-other-providers)

```
When you instantiate your provider, you can also pass a second parameter containing a collaborator for your httpClient.
Doing that means you can define your own Guzzle client and do things such as:

  1. Setting Guzzle into debug mode, or
  2. Adding a rate limiter mildeware (composer require spatie/guzzle-rate-limiter-middleware)

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Spatie\GuzzleRateLimiterMiddleware\RateLimiterMiddleware;

// Add a rate limiter
$stack=HandlerStack::create();
$stack->push(RateLimiterMiddleware::perSecond($this->getPerSecondRateLimit()));
$options=['debug' => $debug, 'exceptions' => false, 'handler' => $stack];
$httpClient = new Client($options);

$this->provider = \GlobalVisionMedia\OAuth2\MYOBClient\Provider\MYOB([
    'redirectUri'       => CALLBACK_URI,
    'clientId'          => MYOB_CLIENT_ID,
    'clientSecret'      => MYOB_CLIENT_SECRET,
    'username'          => MYOB_USERNAME,
    'password'          => MYOB_PASSWORD,
    'companyName'       => MYOB_COMPANY_NAME
  ],
  ['httpClient'         => $httpClient]);

```

Sample application
==================

[](#sample-application)

```
